fix: reject TechLog protocol-relative links

This commit is contained in:
DongHyeonka
2026-08-15 19:10:05 +09:00
parent 8342fb14dc
commit 708680b28e
2 changed files with 6 additions and 1 deletions
@@ -199,6 +199,7 @@ function isSafeLink(href: string): boolean {
return false;
}
if (href.startsWith("#")) return true;
if (href.startsWith("//")) return false;
if (href.startsWith("/")) {
try {
return (
@@ -39,6 +39,9 @@ describe("Content Format v1", () => {
"<script>alert(1)</script>",
"[x](javascript:alert(1))",
"[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](</safe\u0001path>)",
@@ -75,7 +78,7 @@ describe("Content Format v1", () => {
it("keeps explicitly allowed links and same-origin paths", () => {
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");
@@ -86,6 +89,7 @@ describe("Content Format v1", () => {
.map((inline) => inline.href),
).toEqual([
"#section",
"/safe/path",
"/safe/path?q=one",
"http://example.com/path",
"https://example.com/path",