开发者

How to limit an Ajax call to run with specific POSIX permissions?

I have a jsTree that calls a RESTful web service to get a list of files and directories. I would like to limit what this web service can do, based on the POSIX permissions of the user who makes that call.

In other words, this specific web service should onl开发者_运维知识库y list files and directories that the user has POSIX permissions to access.

Currently, the web service looks for encrypted data in a cookie, which verifies the user who is logged into the web site. Once the user is authenticated, the web service spits out a response for a folder specified by jsTree (e.g., all the files and directories in /home/userA). The web service is called once again on subdirectories, and again on sub-subdirectories, and so forth.

However, the web service runs with root-level permissions, and so if a different username were somehow specified by userA, e.g. to view /home/userB, then userA could see a list of files and directories that he or she might not have been given rights to see.

Is there some equivalent of suExec that can run a web service with the permissions of a specified user?

If this helps, my specific service is a Perl script, using File::Find::Rule to provide a one-level deep listing of the contents of a specified path.

EDIT

Everything is transmitted over an SSL-encrypted connection.


First of all you have a number of major security errors. If at all possible, you should run your web service with low permissions, not high permissions. That way if someone compromises your web service, they have to work to compromise the box.

Secondly keeping the user name encrypted in a cookie and sending data over http leaves your users open to session hijacking. Considering that you're getting access to their actual user account, this is an issue. Especially given how many people use wireless, and how many kids have access to point and click session hijacking tools like firesheep.

With those points understood, there are a couple of approaches you can take. Assuming that you're using a prefork webserver (rather than multi-threaded), you can use POSIX::setuid to temporarily change yourself to the user you want, and then use it again to return to your normal identity.

The other easy approach is to have a script that is accessible from whatever user the webserver runs as that does the listing. You can use sudoers to make it accessible from the webserver without a password. I would prefer this because it can be done without having to run the webserver as root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜