Skip to content

Commit 8fa3575

Browse files
committed
no inline JS allows us to drop unsafe-inline from our CSP
Jira: IAM-1775
1 parent b1de41c commit 8fa3575

2 files changed

Lines changed: 21 additions & 22 deletions

File tree

public/reload.html

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@
2121
</head>
2222
<body>
2323
<main>Session expired.</main>
24-
<script>
25-
// The client-side code for this is: `src/assets/js/reload.js`, and it's
26-
// only ever called in `src/assets/js/fetcher.js`.
27-
const reload = new URL(
28-
new URLSearchParams(window.location.search).get('reload') || '/',
29-
// If no origin is specified, then use ours.
30-
// e.g. "/foobar.html" ->"https://${document.location.origin}/foobar.html"
31-
// Our client code always specifies an origin, so the extra validation
32-
// below is for non-dino-park users of this file.
33-
window.location.origin
34-
);
35-
// Only redirect internally. External redirects are handled by the
36-
// backend. `reload` uses the current origin when constructing it's
37-
// redirect URL, and so we redo that here to hedge against untrustworthy
38-
// input.
39-
const reloadUrl = new URL(reload.pathname, window.location.origin);
40-
// Preserve the rest of the URL.
41-
reloadUrl.search = reload.search;
42-
reloadUrl.hash = reload.hash;
43-
// Punt to the backend, it'll deal with the 404, etc, etc.
44-
window.location.href = reloadUrl.toString();
45-
</script>
4624
</body>
25+
<script src="reload.js"></script>
4726
</html>

public/reload.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// The client-side code for this is: `src/assets/js/reload.js`, and it's
2+
// only ever called in `src/assets/js/fetcher.js`.
3+
const reload = new URL(
4+
new URLSearchParams(window.location.search).get('reload') || '/',
5+
// If no origin is specified, then use ours.
6+
// e.g. "/foobar.html" ->"https://${document.location.origin}/foobar.html"
7+
// Our client code always specifies an origin, so the extra validation
8+
// below is for non-dino-park users of this file.
9+
window.location.origin
10+
);
11+
// Only redirect internally. External redirects are handled by the
12+
// backend. `reload` uses the current origin when constructing its
13+
// redirect URL, and so we redo that here to hedge against untrustworthy
14+
// input.
15+
const reloadUrl = new URL(reload.pathname, window.location.origin);
16+
// Preserve the rest of the URL.
17+
reloadUrl.search = reload.search;
18+
reloadUrl.hash = reload.hash;
19+
// Punt to the backend, it'll deal with the 404, etc, etc.
20+
window.location.href = reloadUrl.toString();

0 commit comments

Comments
 (0)