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 (#6728)
Co-authored-by: dwelle <luzar.david@gmail.com>
- 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
b33fa6d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
excalidraw-package-example – ./src/packages/excalidraw
excalidraw-package-example.vercel.app
excalidraw-package-example-git-master-excalidraw.vercel.app
excalidraw-package-example-excalidraw.vercel.app