TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The pitfalls of allowing file uploads on your website

100 点作者 BogdanCalin大约 11 年前

8 条评论

ChuckMcM大约 11 年前
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 未加载
tantalor大约 11 年前
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 未加载
callmeed大约 11 年前
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 未加载
tehwebguy大约 11 年前
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.
staunch大约 11 年前
&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 未加载
rebel大约 11 年前
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 未加载
elchief大约 11 年前
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_jones大约 11 年前
Nice post, just goes to show the value of properly validating uploads!