TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The pitfalls of allowing file uploads on your website

100 pointsby BogdanCalinalmost 11 years ago

8 comments

ChuckMcMalmost 11 years ago
The bottom line is this, if users can upload something to your site, and then your site will show that thing to other users before you have a chance to figure out if its a problem, then your site will be exploited by bad actors.<p>For a long time an out of the box server installation would include anonymous ftp access. Of course nothing is quite so attractive as a &#x27;free&#x27; place to dump and retrieve stuff. It was kind of like setting up a warez&#x2F;malware camera trap.
评论 #7775285 未加载
评论 #7775161 未加载
tantaloralmost 11 years ago
Should clarify: &quot;The pitfalls of hosting user-uploaded files on your website&quot;<p>Hosting user-uploaded files on a separate domain would probably solve this problem.
评论 #7775460 未加载
评论 #7774537 未加载
callmeedalmost 11 years ago
Hold-on, doesn&#x27;t using a<p><pre><code> Content-Disposition: attachment; filename=”image.jpg” </code></pre> header mean you can no longer display the image in your service? Won&#x27;t browsers treat it as a file download? Most services that allow image uploads do so because the images will get displayed on a page? (that&#x27;s what I do)<p>Most services seem to be moving file uploads to S3 (or similar services) these days, so I&#x27;m not sure this advice is really helpful. To take that a step further, my preference now is to upload <i>directly</i> to S3 and bypass my app server altogether. At least in Rails, it&#x27;s fairly easy to setup.
评论 #7775595 未加载
tehwebguyalmost 11 years ago
A nice way to achieve this with Rails is to upload straight to S3 and then use Paperclip to get, verify and process the file.<p>By uploading straight to S3 you also get a faster upload (than, say, Heroku) and server separation.
staunchalmost 11 years ago
&gt; <i>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.</i><p>The idea that you can &quot;verify the contents&quot; is pretty much just wrong. You actually have to parse the files and write out your own known-safe version. It&#x27;s a real pain in the butt to do that correctly and securely across a wide variety of file types.<p>Even parsing arbitrary user uploads with something like ImageMagick is probably exploitable, simply because those libraries weren&#x27;t designed to handle hostile input.
评论 #7775889 未加载
评论 #7776179 未加载
评论 #7776963 未加载
rebelalmost 11 years ago
So out of curiosity, what would be the easiest way to <i>securely</i> accept file uploads? Taking into account all of the possible malicious attacks.
评论 #7776472 未加载
elchiefalmost 11 years ago
I&#x27;m pretty sure you can use Apache Tika to check the actual content type of a file too. Either way, I hate flash.
tom_jonesalmost 11 years ago
Nice post, just goes to show the value of properly validating uploads!