Skip to content

Commit

Permalink
Merge pull request #2756 from AnnMarieW/fix-xss
Browse files Browse the repository at this point in the history
Check href before sanitize url
  • Loading branch information
alexcjohnson authored Feb 9, 2024
2 parents f27810f + a17a2c7 commit 91b6acf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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
6 changes: 4 additions & 2 deletions components/dash-core-components/src/components/Link.react.js
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() == []

0 comments on commit 91b6acf

Please # to comment.