Skip to content

Commit

Permalink
Merge 9fb851d into backport/SECVULN-6915-consul-enterprise-Client-sid…
Browse files Browse the repository at this point in the history
…e-cross-site-scripting-in-ui-packages-consul-ui-app-utils-get-environment.js-62/terribly-quick-grub
  • Loading branch information
hc-github-team-consul-core authored Sep 12, 2024
2 parents 47d8aa4 + 9fb851d commit 20f20d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/21711.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:security
Implement HTML sanitization for user-generated content to prevent XSS attacks in the UI.
```
26 changes: 23 additions & 3 deletions ui/packages/consul-ui/app/utils/get-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
`);
}
}
};

Expand Down

0 comments on commit 20f20d3

Please sign in to comment.