Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check href before sanitize url #2756

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

## Fixed

- [#2756](https://github.com/plotly/dash/pull/2756) Prevent false dangerous link warning. Fixes [#2743](https://github.com/plotly/dash/issues/2743)

## Changed

- [#2734](https://github.com/plotly/dash/pull/2734) Configure CI for Python 3.10 [#1863](https://github.com/plotly/dash/issues/1863)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const Link = props => {
refresh,
setProps,
} = props;
const sanitizedUrl = useMemo(() => sanitizeUrl(href), [href]);
const sanitizedUrl = useMemo(() => {
return href ? sanitizeUrl(href) : undefined;
}, [href]);

const updateLocation = e => {
const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey;
Expand All @@ -70,7 +72,7 @@ const Link = props => {
};

useEffect(() => {
if (sanitizedUrl !== href) {
if (sanitizedUrl && sanitizedUrl !== href) {
setProps({
_dash_error: new Error(`Dangerous link detected:: ${href}`),
});
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/security/test_xss.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ def test_xss001_banned_protocols(dash_duo):
assert (
element.get_attribute(prop) == "about:blank"
), f"Failed prop: {element_id}.{prop}"


def test_xss002_blank_href(dash_duo):
app = Dash()

app.layout = html.Div(dcc.Link("dcc-link", href="", id="dcc-link-no-href"))

dash_duo.start_server(app)

element = dash_duo.find_element("#dcc-link-no-href")
assert element.get_attribute("href") is None

assert dash_duo.get_logs() == []