Skip to content

Commit 91b6acf

Browse files
authored
Merge pull request #2756 from AnnMarieW/fix-xss
Check href before sanitize url
2 parents f27810f + a17a2c7 commit 91b6acf

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
44

55
## [UNRELEASED]
66

7+
## Fixed
8+
9+
- [#2756](https://github.com/plotly/dash/pull/2756) Prevent false dangerous link warning. Fixes [#2743](https://github.com/plotly/dash/issues/2743)
10+
711
## Changed
812

913
- [#2734](https://github.com/plotly/dash/pull/2734) Configure CI for Python 3.10 [#1863](https://github.com/plotly/dash/issues/1863)

components/dash-core-components/src/components/Link.react.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ const Link = props => {
4646
refresh,
4747
setProps,
4848
} = props;
49-
const sanitizedUrl = useMemo(() => sanitizeUrl(href), [href]);
49+
const sanitizedUrl = useMemo(() => {
50+
return href ? sanitizeUrl(href) : undefined;
51+
}, [href]);
5052

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

7274
useEffect(() => {
73-
if (sanitizedUrl !== href) {
75+
if (sanitizedUrl && sanitizedUrl !== href) {
7476
setProps({
7577
_dash_error: new Error(`Dangerous link detected:: ${href}`),
7678
});

tests/integration/security/test_xss.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ def test_xss001_banned_protocols(dash_duo):
4545
assert (
4646
element.get_attribute(prop) == "about:blank"
4747
), f"Failed prop: {element_id}.{prop}"
48+
49+
50+
def test_xss002_blank_href(dash_duo):
51+
app = Dash()
52+
53+
app.layout = html.Div(dcc.Link("dcc-link", href="", id="dcc-link-no-href"))
54+
55+
dash_duo.start_server(app)
56+
57+
element = dash_duo.find_element("#dcc-link-no-href")
58+
assert element.get_attribute("href") is None
59+
60+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)