-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_fix.js
More file actions
31 lines (27 loc) · 816 Bytes
/
Copy pathverify_fix.js
File metadata and controls
31 lines (27 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const error = {
message: 'Something went wrong <img src=x onerror=alert(1)>'
};
function escapeHTML(str) {
const div = {
textContent: '',
get innerHTML() {
return this.textContent
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
};
div.textContent = 'Error rendering markdown: ' + str;
return div.innerHTML;
}
console.log('Testing security fix logic...');
const escaped = escapeHTML(error.message);
console.log('Escaped output:', escaped);
if (escaped.includes('<img')) {
console.error('FAILED: HTML was not escaped!');
process.exit(1);
} else {
console.log('PASSED: HTML was escaped.');
}