fix: harden automatic mobile boards
This commit is contained in:
1 parent
5454bcc8ac
commit
967ed8dd73
25 files changed
+490
-92
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { sanitizeFeedDescription } from "./sanitize-description";
|
||||
|
||||
describe("sanitizeFeedDescription", () => {
|
||||
test("keeps basic formatting while removing executable markup", () => {
|
||||
const description =
|
||||
'<p onclick="alert(1)" aria-hidden="true" data-tracking="yes">News <strong>today</strong><script>alert(2)</script><img src="tracker"></p>';
|
||||
|
||||
expect(sanitizeFeedDescription(description)).toBe("<p>News <strong>today</strong></p>");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { sanitize } from "isomorphic-dompurify";
|
||||
|
||||
const allowedDescriptionTags = ["b", "br", "em", "i", "li", "ol", "p", "s", "strong", "u", "ul"];
|
||||
|
||||
export const sanitizeFeedDescription = (description: string) =>
|
||||
sanitize(description, {
|
||||
ALLOW_ARIA_ATTR: false,
|
||||
ALLOW_DATA_ATTR: false,
|
||||
ALLOWED_ATTR: [],
|
||||
ALLOWED_TAGS: allowedDescriptionTags,
|
||||
});
|
||||
Reference in new issue
Block a user