Backport of [ui] Simple url sanitization for get-env and document.cookie into release/1.19.x (#21721)

backport of commit 9fb851ddd2

Co-authored-by: Phil Renaud <phil@riotindustries.com>
pull/21732/head
hc-github-team-consul-core 3 months ago committed by GitHub
parent c0c9b5b2b9
commit 39c00d3271
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
```release-note:security
Implement HTML sanitization for user-generated content to prevent XSS attacks in the UI.
```

@ -4,6 +4,19 @@
*/
import { runInDebug } from '@ember/debug';
import { htmlSafe } from '@ember/template';
function sanitizeString(str) {
return htmlSafe(
String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
);
}
// 'environment' getter
// there are currently 3 levels of environment variables:
// 1. Those that can be set by the user by setting localStorage values
@ -58,9 +71,16 @@ export default function (config = {}, win = window, doc = document) {
} else {
str = cookies(doc.cookie).join(';');
const tab = win.open('', '_blank');
tab.document.write(
`<body><pre>${location.href}#${str}</pre><br /><a href="javascript:Scenario('${str}')">Scenario</a></body>`
);
if (tab) {
const safeLocationHref = sanitizeString(location.href);
const safeStr = sanitizeString(str);
tab.document.write(`
<body>
<pre>${safeLocationHref}#${safeStr}</pre><br />
<a href="#" onclick="window.opener.Scenario('${safeStr}');window.close();return false;">Scenario</a>
</body>
`);
}
}
};

Loading…
Cancel
Save