Live data from Hacker News

The pitfalls of allowing file uploads on your website

blog.detectify.com

21–30 of 32 posts

Re: The pitfalls of allowing file uploads on your website

#21
post #4
post #3

Earlier quoted context omitted.

How does simply using a different domain protect against malware?

As the article explains, the problem is that SWF files hosted on one domain can execute in the security context of that domain, even when embedded in a page on a completely different site. So allowing attacker-controlled uploads makes any credentials on that domain, such as session cookies and CSRF tokens, vulnerable. If the SWF is hosted on a domain with no sensitive credentials, this particular problem goes away.

I don't understand. How does serving a flash applet from my domain get you access to anything other than that applet?

I'm not arguing that this attack doesn't exist. I just don't understand what the attacker gets access to.

Re: The pitfalls of allowing file uploads on your website

#23
post #13

> So if you allow file uploads or printing arbitrary user data in your service, you should always verify the contents as well as sending a Content-Disposition header where applicable. The idea that you can "verify the contents" is pretty much just wrong. You actually have to parse the files and write out your own known-safe version. It's a real pain in the butt to do that correctly and securely across a wide variety…

Isn't it a reasonable workaround to scan the file for content-type and make the file available once it passes the criteria for the upload? Find a php file uploaded with an extension of .jpg? "Sorry, there was a problem with your file. Please try again."

Re: The pitfalls of allowing file uploads on your website

#24
post #23
post #13

> So if you allow file uploads or printing arbitrary user data in your service, you should always verify the contents as well as sending a Content-Disposition header where applicable. The idea that you can "verify the contents" is pretty much just wrong. You actually have to parse the files and write out your own known-safe version. It's a real pain in the butt to do that correctly and securely across a wide variety…

Isn't it a reasonable workaround to scan the file for content-type and make the file available once it passes the criteria for the upload? Find a php file uploaded with an extension of .jpg? "Sorry, there was a problem with your file. Please try again."

And then you run into polyglot files which are valid for multiple types...

Re: The pitfalls of allowing file uploads on your website

#25
post #16
post #9

Earlier quoted context omitted.

Even if it does not show anything to other users, just having the wrong extension can already bite you badly. Uploading php files instead of images has been used to gain access to machines. Anything that gets stored as a file on the filesystem of the destination machine is a huge risk. All it takes is one little misconfiguration somewhere else and you're wide open.

This is only if you subsequently give them a link to what they uploaded, correct? I have a site that allows uploads (students turning in Java files) but the files are just stored in a folder on the server that isn't in the web-served path. They can't see the file again once uploaded. I assume (and I think rightly) that there's no security risk in my case.

As long as you read the files before you execute them.

Otherwise some bad actor could write a virus / local exploit into their submission which will execute when you compile and run the file.

Re: The pitfalls of allowing file uploads on your website

#26
post #22

So out of curiosity, what would be the easiest way to securely accept file uploads? Taking into account all of the possible malicious attacks.

Host them on a separate domain like Google and Github does (eg. Google uses googleusercontent.com and Github uses githubusercontent.com).

Re: The pitfalls of allowing file uploads on your website

#27
post #21
post #4

Earlier quoted context omitted.

As the article explains, the problem is that SWF files hosted on one domain can execute in the security context of that domain, even when embedded in a page on a completely different site. So allowing attacker-controlled uploads makes any credentials on that domain, such as session cookies and CSRF tokens, vulnerable. If the SWF is hosted on a domain with no sensitive credentials, this particular problem goes away.

I don't understand. How does serving a flash applet from my domain get you access to anything other than that applet? I'm not arguing that this attack doesn't exist. I just don't understand what the attacker gets access to.

Browser security relies on the "same origin policy" which says that certain operations are restricted to only access resources in the same domain as the active page. In particular, you can't read cookies from another domain, and you can't read the responses of authenticated HTTP requests. XSS and CSRF attacks all rely on an circumventing this protection in various ways.

In this case, Flash considers the origin to be the location of the SWF file. This is different from normal JavaScript where all scripts in a page run under that page's origin, no matter where they're loaded from.

Re: The pitfalls of allowing file uploads on your website

#28
post #16

Earlier quoted context omitted.

This is only if you subsequently give them a link to what they uploaded, correct? I have a site that allows uploads (students turning in Java files) but the files are just stored in a folder on the server that isn't in the web-served path. They can't see the file again once uploaded. I assume (and I think rightly) that there's no security risk in my case.

As long as you read the files before you execute them. Otherwise some bad actor could write a virus / local exploit into their submission which will execute when you compile and run the file.

I never execute them. I just grade them by reading the code. Running them takes FAR longer than reading.

Re: The pitfalls of allowing file uploads on your website

#30
post #13

> So if you allow file uploads or printing arbitrary user data in your service, you should always verify the contents as well as sending a Content-Disposition header where applicable. The idea that you can "verify the contents" is pretty much just wrong. You actually have to parse the files and write out your own known-safe version. It's a real pain in the butt to do that correctly and securely across a wide variety…

[deleted]
Post reply on HN