dpicx06888 2013-07-26 19:02
浏览 62
已采纳

通过外部URL允许图像配置文件的最佳安全方式[关闭]

Suppose that I have a web application where users can attach a link in their profile to show the avatar (displayed after with img tag).

This is safe? I think it is not.

What is the best way to check if the url provided is a real image? There are other solutions? (for now I don't want any upload).

  • 写回答

3条回答 默认 最新

  • duanliaoyin3171 2013-07-26 19:50
    关注

    No, it is not safe. This approach is vulnerable to XSS (Cross-Site Scripting) and CSRF (Cross-Site Request Forgery) attacks. Number of ways to construct possible XSS attacks with img tags is huge. Have a look at OWASP list Malformed img tags just to give you an idea.

    You may say that escaping can help you. Yes it is, but escaping alone does not guarantee XSS prevention. Here is what OWASP (The Open Web Application Security Project) recommends in general:

    You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into

    Plus check what data is allowed (white list) instead of checking endless list of not allowed data. Here is OWASP's XSS prevention cheat sheet. OWASP also released a library ESAPI to be used for escaping in the right context.

    But let's say you are done with XSS. With CSRF malicious user can construct legitimate request inside your img tag for updating some user's profile. And let's say such user comes to see this profile and all of the sudden his/her profile is updated! In this case you will probably need to generate "challenge" / validation token associated with user's session which will be attached to each user's request.

    My recommendation is either use external trusted service like gravatar or implement upload. If you do want to use user's input then I strongly encourage you to familiarize yourself with ESAPI library for this case and OWASP XSS and CSRF prevention cheat sheets.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用