Live data from Hacker News

If your code accepts URIs as input, filter out “file://”

blog.steve.fi

11–20 of 161 posts

Re: If your code accepts URIs as input, filter out “file://”

#11

Wrong way around: only allow http:// and https:// (and generally filtering out anything thats not letters, numbers, slash or dot is probably a good idea. Remove any sequences of more than one slash or dot.

(Also be weary of imagetragick-type bugs too, where the URL starts innocuously and then contains some shellcode, because you pass the URL to something that'll paste it into system() call)

Re: If your code accepts URIs as input, filter out “file://”

#13

This is the confused deputy problem. The most general solution to this class of vulnerabilities, SELinux, has been largely ignored. Does SELinux need more work to "bring it to market", or is it just too complicated and needs to be simplified?

configuring SELinux is way too complicated for the average user.

Re: If your code accepts URIs as input, filter out “file://”

#14
post #13

This is the confused deputy problem. The most general solution to this class of vulnerabilities, SELinux, has been largely ignored. Does SELinux need more work to "bring it to market", or is it just too complicated and needs to be simplified?

configuring SELinux is way too complicated for the average user.

And poorly documented. I learned what little I know about it from online tutorials, not the docs

Re: If your code accepts URIs as input, filter out “file://”

#15
post #8

I usually only do this, if I'm putting a user-submitted URL into file_get_contents: if(substr($_GET['url'], 0, 4) != 'http') { exit; }

If thats the only validation on calls to file_get_contents, that could very easily be bypassed. Entering something like just "/etc/passwd" for example.

/etc != http :)

Re: If your code accepts URIs as input, filter out “file://”

#16

This is the confused deputy problem. The most general solution to this class of vulnerabilities, SELinux, has been largely ignored. Does SELinux need more work to "bring it to market", or is it just too complicated and needs to be simplified?

SELinux is a real burden for even motivated sysadmins.

However, if you have a single image that you are going to make millions of copies of then the effort vs reward might slant in SELinux's favour, e.g. Android does use SELinux.

Re: If your code accepts URIs as input, filter out “file://”

#17
This is a special case of a Server-Side Request Forget vulnerability. Validating schemes is part of the answer but not the whole answer because attackers can still forge requests to internal resources you have firewalled off from the internet.

These were recently released to help people deal with these issues since the details can be finicky: http://blog.includesecurity.com/2016/08/safeurl-server-side-...

Re: If your code accepts URIs as input, filter out “file://”

#18
post #12

I tried Python requests and Common Lisp drakma, and neither of them can handle "file://" URL schema. Which HTTP client libraries are actually vulnerable to this?

The most popular HTTP library is libcurl, and it supports file URLs by default.

Re: If your code accepts URIs as input, filter out “file://”

#20
post #9

Wrong way around: only allow http:// and https:// (and generally filtering out anything thats not letters, numbers, slash or dot is probably a good idea. Remove any sequences of more than one slash or dot.

Exactly. Whitelist only trusted schemes, do not wait to blacklist untrusted. I wrote the Go HTML sanitizer: https://github.com/microcosm-cc/bluemonday and have a rule for user generated (untrusted) content that basically does whitelist just the things that one can trust: https://github.com/microcosm-cc/bluemonday/blob/master/helpe... That states that URIs must be: 1. Parseable 2. Relative 3. Or one of: mailto http ht…

[deleted]
Post reply on HN