简体   繁体   English

如何在Laravel中限制与管理员相关的AngularJs控制器?

[英]How to restrict admin related AngularJs Controllers in Laravel?

In Laravel , you can restrict access to some Controllers (eg. Admin-related controllers such as Admin/UsersController, Admin/SettingsController, etc.) to specific user sessions. Laravel中 ,您可以将对某些控制器(例如,与Admin相关的控制器,例如Admin / UsersController,Admin / SettingsController等)的访问限制为特定的用户会话。 Because it's server-side, the user has no-way to snoop-out about such controllers unless authenticated. 由于它是服务器端的,除非经过身份验证,否则用户无法窥探此类控制器。

In the case of AngularJs 's, the code resides in the browser. AngularJs的情况下,代码驻留在浏览器中。 Thus, anyone can get a look at the javascript source codes and might figure-out the behaviour of the app. 因此,任何人都可以看一下javascript源代码,并且可以弄清楚应用程序的行为。 Say he might discover that there are controllers that manage admin-related data. 假设他可能发现有些控制器可以管理与管理员相关的数据。 Or anyone might try to brute-force-search the app's URL for javascript files to observe. 否则,任何人都可能尝试强行搜索应用程序的URL,以查看要观察的javascript文件。 Say he looks at http://myapp.com/AdminSettingsController.js in which authenticated users should only be able to see or should not at all. 假设他查看了http://myapp.com/AdminSettingsController.js ,其中经过身份验证的用户应该只能看到或根本不应该看到。

Going back to the main question, how do you resolve such issues? 回到主要问题,您如何解决此类问题?

This problem has only one solution. 这个问题只有一个解决方案。 Treat JavaScript as language for your User Interface only. 仅将JavaScript视为用户界面的语言。 Nothing more than that. 仅此而已。 Don't store any sensitive data in browser, don't store any sensitive logic (eg database queries) either. 不要在浏览器中存储任何敏感数据,也不要存储任何敏感逻辑(例如数据库查询)。 There is no way to hide network traffic or source code from client . 无法从客户端隐藏网络流量或源代码

I usually create some sort of user object on client side, which contains users role for resolving permissions, and I use the permission for display controls, eg show some buttons only to admin etc. BUT, this only affects the displaying of the page, If user interacts with that controls, the controls rely on the server and if the user does not have proper permissions on the server as well, the interaction with the control fails, so if anyone with some knowledge change the user object on the client and grants him administrator role, he only sees the control what the administrator would see, but he can not make administrator actions nor he sees any sensitive data. 我通常在客户端创建某种用户对象,其中包含用于解决权限的用户角色,并且我将权限用于显示控件,例如仅向admin等显示一些按钮。但是,这只会影响页面的显示 ,如果用户与该控件进行交互,控件依赖于服务器,并且如果用户对服务器也没有适当的权限,则与控件的交互将失败,因此,如果任何有知识的人更改了客户端上的用户对象并授予了他权限管理员角色,他只能看到管理员看到的控件,但是他无法执行管理员操作,也看不到任何敏感数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM