Skip to content

Commit 7c8070a

Browse files
authored
fix: add noreferrer to external markdown links to prevent 403 errors (#7360)
## Summary Fixes #7350 by adding `noreferrer` to the `rel` attribute of external links in markdown cells. This prevents the browser from sending the `Referer` header when clicking links, which was causing some websites (like ScienceDirect) to return 403 errors when detecting `localhost` as the referrer.
1 parent 29a5ae2 commit 7c8070a

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

frontend/src/plugins/core/__test__/sanitize.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("sanitizeHtml", () => {
6464
test("preserves safe anchor with target=_blank", () => {
6565
const html = '<a href="https://example.com" target="_blank">Link</a>';
6666
expect(sanitizeHtml(html)).toMatchInlineSnapshot(
67-
`"<a href="https://example.com" target="_blank" rel="noopener">Link</a>"`,
67+
`"<a href="https://example.com" target="_blank" rel="noopener noreferrer">Link</a>"`,
6868
);
6969
});
7070

frontend/src/plugins/core/sanitize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ DOMPurify.addHook("afterSanitizeAttributes", (node) => {
6262
node.setAttribute("target", node.getAttribute(TEMPORARY_ATTRIBUTE) || "");
6363
node.removeAttribute(TEMPORARY_ATTRIBUTE);
6464
if (node.getAttribute("target") === "_blank") {
65-
node.setAttribute("rel", "noopener");
65+
node.setAttribute("rel", "noopener noreferrer");
6666
}
6767
}
6868
});

marimo/_output/md_extensions/external_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run(self, root: Element) -> None:
2828

2929
if parsed_url.scheme in ["http", "https"]:
3030
element.set("target", "_blank")
31-
element.set("rel", "noopener")
31+
element.set("rel", "noopener noreferrer")
3232

3333

3434
class ExternalLinksExtension(Extension): # type: ignore[misc]

tests/_output/test_md.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_md_latex() -> None:
7373
def test_md_links() -> None:
7474
# Test external link conversion
7575
link_input = "[Google](https://google.com)"
76-
expected_output = '<span class="paragraph"><a href="https://google.com" rel="noopener" target="_blank">Google</a></span>' # noqa: E501
76+
expected_output = '<span class="paragraph"><a href="https://google.com" rel="noopener noreferrer" target="_blank">Google</a></span>' # noqa: E501
7777
assert _md(link_input, apply_markdown_class=False).text == (
7878
expected_output
7979
)

0 commit comments

Comments
 (0)