-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6778c4e
commit 1aa6282
Showing
6 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
"@comet/cms-api": patch | ||
--- | ||
|
||
Improve SVG validation | ||
|
||
Following tags are banned in SVGs: | ||
|
||
- script | ||
- \[new\] foreignObject | ||
- \[new\] use | ||
- \[new\] image | ||
- \[new\] animate | ||
- \[new\] animateMotion | ||
- \[new\] animateTransform | ||
- \[new\] set | ||
|
||
Following attributes are banned: | ||
|
||
- Event handlers (`onload`, `onclick`, ...) | ||
- \[new\] `href` and `xlink:href` (if the value starts with `http://`, `https://` or `javascript:`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
import { svgContainsJavaScript } from "./files.utils"; | ||
import { isValidSvg } from "./files.utils"; | ||
|
||
describe("Files Utils", () => { | ||
describe("svgContainsJavaScript", () => { | ||
it("should return false if the svg doesn't contain a script tag or event handler", async () => { | ||
describe("isValidSvg", () => { | ||
it("should return true if the svg doesn't contain any forbidden content", async () => { | ||
const cleanSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"> | ||
<path fill="#242424" fill-rule="evenodd" d=""/> | ||
</svg>`; | ||
|
||
expect(svgContainsJavaScript(cleanSvg)).toBe(false); | ||
expect(isValidSvg(cleanSvg)).toBe(true); | ||
}); | ||
|
||
it("should return true if the svg contains a script tag", async () => { | ||
it("should return false if the svg contains a script tag", async () => { | ||
const svgWithScriptTag = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"> | ||
<path fill="#242424" fill-rule="evenodd" d=""/> | ||
<script type="text/javascript"> | ||
alert("XSS"); | ||
</script> | ||
</svg>`; | ||
|
||
expect(svgContainsJavaScript(svgWithScriptTag)).toBe(true); | ||
expect(isValidSvg(svgWithScriptTag)).toBe(false); | ||
}); | ||
|
||
it("should return true if the svg contains an event handler", async () => { | ||
it("should return false if the svg contains an event handler", async () => { | ||
const svgWithOnloadHandler = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"> | ||
<path onload="alert('XSS');" fill="#242424" fill-rule="evenodd" d=""/> | ||
</svg>`; | ||
|
||
expect(svgContainsJavaScript(svgWithOnloadHandler)).toBe(true); | ||
expect(isValidSvg(svgWithOnloadHandler)).toBe(false); | ||
}); | ||
|
||
it("should return false if the svg contains a href attribute containing javascript", async () => { | ||
const svgWithOnloadHandler = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"> | ||
<a href="javascript:alert(1)"> | ||
<path onload="alert('XSS');" fill="#242424" fill-rule="evenodd" d=""/> | ||
</a> | ||
</svg>`; | ||
|
||
expect(isValidSvg(svgWithOnloadHandler)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters