forked from excalidraw/excalidraw
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stronger enforcement of normalizeLink (excalidraw#6728)
Co-authored-by: dwelle <[email protected]>
- Loading branch information
Showing
10 changed files
with
72 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { normalizeLink } from "./url"; | ||
|
||
describe("normalizeLink", () => { | ||
// NOTE not an extensive XSS test suite, just to check if we're not | ||
// regressing in sanitization | ||
it("should sanitize links", () => { | ||
expect( | ||
// eslint-disable-next-line no-script-url | ||
normalizeLink(`javascript://%0aalert(document.domain)`).startsWith( | ||
// eslint-disable-next-line no-script-url | ||
`javascript:`, | ||
), | ||
).toBe(false); | ||
expect(normalizeLink("ola")).toBe("ola"); | ||
expect(normalizeLink(" ola")).toBe("ola"); | ||
|
||
expect(normalizeLink("https://www.excalidraw.com")).toBe( | ||
"https://www.excalidraw.com", | ||
); | ||
expect(normalizeLink("www.excalidraw.com")).toBe("www.excalidraw.com"); | ||
expect(normalizeLink("/ola")).toBe("/ola"); | ||
expect(normalizeLink("http://test")).toBe("http://test"); | ||
expect(normalizeLink("ftp://test")).toBe("ftp://test"); | ||
expect(normalizeLink("file://")).toBe("file://"); | ||
expect(normalizeLink("file://")).toBe("file://"); | ||
expect(normalizeLink("[test](https://test)")).toBe("[test](https://test)"); | ||
expect(normalizeLink("[[test]]")).toBe("[[test]]"); | ||
expect(normalizeLink("<test>")).toBe("<test>"); | ||
}); | ||
}); |
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,9 @@ | ||
import { sanitizeUrl } from "@braintree/sanitize-url"; | ||
|
||
export const normalizeLink = (link: string) => { | ||
return sanitizeUrl(link); | ||
}; | ||
|
||
export const isLocalLink = (link: string | null) => { | ||
return !!(link?.includes(location.origin) || link?.startsWith("/")); | ||
}; |
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
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 |
---|---|---|
|
@@ -1086,6 +1086,11 @@ | |
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" | ||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== | ||
|
||
"@braintree/[email protected]": | ||
version "6.0.2" | ||
resolved "https://registry.yarnpkg.com/@braintree/sanitize-url/-/sanitize-url-6.0.2.tgz#6110f918d273fe2af8ea1c4398a88774bb9fc12f" | ||
integrity sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg== | ||
|
||
"@csstools/normalize.css@*": | ||
version "12.0.0" | ||
resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-12.0.0.tgz#a9583a75c3f150667771f30b60d9f059473e62c4" | ||
|