Include an SVG (hosted on GitHub) in MarkDown

后端 未结 8 1800
执笔经年
执笔经年 2020-12-07 07:49

I know with that an image can be placed in a MD with the MD syntax of either ![Alt text](/path/to/img.jpg) or ![Alt text](/path/to/img.jpg "Optional

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 08:17

    Update 2020: how they made it work while avoiding XSS attacks

    GitHub appears to use two security approaches, this is a good article: https://digi.ninja/blog/svg_xss.php see also: https://security.stackexchange.com/questions/148507/how-to-prevent-xss-in-svg-file-upload

    • show SVG inside tag, which prevents scripts from running, e.g. on READMEs: https://github.com/cirosantilli/test-git-web-interface/tree/8e394cdb012cba4bcf55ebdb89f36872b4c6c12a

    • use Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; sandbox. This prevents the script from running even in raw which contains the raw SVG file: https://raw.githubusercontent.com/cirosantilli/test-git-web-interface/8e394cdb012cba4bcf55ebdb89f36872b4c6c12a/svg-foreignObject.svg

      You can see the header with curl -vvv. The regular github.com pages also have a content-security-policy, but it is much larger.

    Update 2017

    A GitHub dev is currently looking into this: https://github.com/github/markup/issues/556#issuecomment-306103203

    Update 2014-12: GitHub now renders SVG on blob show, so I don't see any reason why not to render on README renderings:

    • https://github.com/blog/1902-svg-viewing-diffing
    • https://github.com/cirosantilli/test/blob/2144a93333be144152e8b0d4144b77b211afce63/svg.svg

    Also note that that SVG does have an XSS attempt but it does not run: https://raw.githubusercontent.com/cirosantilli/test/2144a93333be144152e8b0d4144b77b211afce63/svg.svg

    The billion laugh SVG does make Firefox 44 Freeze, but Chromium 48 is OK: https://github.com/cirosantilli/web-cheat/blob/master/svg-billion-laughs.svg

    Petah mentioned that blobs are fine because the SVG is inside an iframe.

    Possible rationale for GitHub not serving SVG images

    • general XML vulnerabilities. E.g. opening a billion laughs exploit just made Firefox crash my system. Firefox bug with exploit attached: https://bugzilla.mozilla.org/page.cgi?id=voting/user.html. Same on Chromium: https://code.google.com/p/chromium/issues/detail?id=231562

    • SVG XSS scripting: while most browsers don't run scripts when the SVG is embedded with img, it seems that this is not required by the standards, so maybe GitHub is playing it safe.

      Browsers do run it if you open the SVG directly (but it appears that GitHub never shows images directly on the github.com domain) or if it is inline (which are currently completely removed by GitHub), so those cases shouldn't be a security concern. Relevant links:

      • spec: http://www.w3.org/TR/SVG/script.html
      • interactive SVG demo: http://www.w3.org/TR/SVG/images/script/script01.svg

    The following questions asks about the risks of SVG in general: https://security.stackexchange.com/questions/11384/exploits-or-other-security-risks-with-svg-upload

提交回复
热议问题