fix: reject TechLog protocol-relative links
This commit is contained in:
@@ -199,6 +199,7 @@ function isSafeLink(href: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (href.startsWith("#")) return true;
|
if (href.startsWith("#")) return true;
|
||||||
|
if (href.startsWith("//")) return false;
|
||||||
if (href.startsWith("/")) {
|
if (href.startsWith("/")) {
|
||||||
try {
|
try {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ describe("Content Format v1", () => {
|
|||||||
"<script>alert(1)</script>",
|
"<script>alert(1)</script>",
|
||||||
"[x](javascript:alert(1))",
|
"[x](javascript:alert(1))",
|
||||||
"[x](//evil.example/path)",
|
"[x](//evil.example/path)",
|
||||||
|
"[x](//techlog.invalid/path)",
|
||||||
|
"[x](///techlog.invalid/path)",
|
||||||
|
"[x](//user@techlog.invalid/path)",
|
||||||
"[x](/\\evil.example/path)",
|
"[x](/\\evil.example/path)",
|
||||||
"[x](/\\\\evil.example/path)",
|
"[x](/\\\\evil.example/path)",
|
||||||
"[x](</safe\u0001path>)",
|
"[x](</safe\u0001path>)",
|
||||||
@@ -75,7 +78,7 @@ describe("Content Format v1", () => {
|
|||||||
|
|
||||||
it("keeps explicitly allowed links and same-origin paths", () => {
|
it("keeps explicitly allowed links and same-origin paths", () => {
|
||||||
const [paragraph] = parseCaseContent(
|
const [paragraph] = parseCaseContent(
|
||||||
"[fragment](#section) [path](/safe/path?q=one) [http](http://example.com/path) [https](https://example.com/path) [mail](mailto:test@example.com)",
|
"[fragment](#section) [path](/safe/path) [query](/safe/path?q=one) [http](http://example.com/path) [https](https://example.com/path) [mail](mailto:test@example.com)",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(paragraph?.type).toBe("PARAGRAPH");
|
expect(paragraph?.type).toBe("PARAGRAPH");
|
||||||
@@ -86,6 +89,7 @@ describe("Content Format v1", () => {
|
|||||||
.map((inline) => inline.href),
|
.map((inline) => inline.href),
|
||||||
).toEqual([
|
).toEqual([
|
||||||
"#section",
|
"#section",
|
||||||
|
"/safe/path",
|
||||||
"/safe/path?q=one",
|
"/safe/path?q=one",
|
||||||
"http://example.com/path",
|
"http://example.com/path",
|
||||||
"https://example.com/path",
|
"https://example.com/path",
|
||||||
|
|||||||
Reference in New Issue
Block a user