Browse Source

[ui] Simple url sanitization for get-env and document.cookie (#21711)

Simple url sanitization for get-env and document.cookie
pull/21722/head
Phil Renaud 2 months ago committed by GitHub
parent
commit
0cc0fa7188
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .changelog/21711.txt
  2. 26
      ui/packages/consul-ui/app/utils/get-environment.js

3
.changelog/21711.txt

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

26
ui/packages/consul-ui/app/utils/get-environment.js

@ -4,6 +4,19 @@
*/
import { runInDebug } from '@ember/debug';
import { htmlSafe } from '@ember/template';
function sanitizeString(str) {
return htmlSafe(
String(str)
.replace(/&/g, '&')
.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