mirror of https://github.com/status-im/consul.git
[ui] Simple url sanitization for get-env and document.cookie (#21711)
Simple url sanitization for get-env and document.cookie
This commit is contained in:
parent
a3ac555a5e
commit
0cc0fa7188
|
@ -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, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
);
|
||||
}
|
||||
|
||||
// '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…
Reference in New Issue