I am using Google Chrome version 98 for this.
I've noticed that when I have a window.prompt and I input <script>, it returns a string with the value of \x3Cscript> instead of <script>. This is odd to me because if I just input <, then it returns <. Only when I input <script> does it change the first angle bracket to its hex code; inputting <a> returns <a>, even inputting <scrip returns <scrip. What I am asking is, does the Javascript engine inside a browser do this parsing internally to prevent injecting Javascript? How does the window.prompt function work internally? I've tried searching for how window.prompt works and could not find anything related to this.
EDIT: I ask this question because I originally was testing out writing a cookie based on user input, and then making a greeting based on the cookie value. Here is the code:
const header = document.getElementById('survey-header');
if (document.cookie.split(';').some(item => item.trim().startsWith('name='))) {
name = document.cookie
.split('; ')
.find(row => row.startsWith('name='))
.split('=')[1];
} else {
name = window.prompt('Please enter your name', 'User');
document.cookie = 'name=' + name
}
/* Set header to greeting message */
header.textContent = 'Greetings, ' + name
But I noticed that when I try to inject Javascript into the prompt, the header is displayed as Greetings, \x3Cscript>...</script>. That made me curious why only some angle brackets are displayed as their hex code.
"\x3C"is"<". That’s just how the console displays this, possibly to mitigate XSS. It has nothing to do withprompt. Have you tried puttingfoo = "<script>"directly into the console? This is all you need to reproduce it in the latest stable Chromium.</script>becomes\x3C/script>. Maybe it's some legacy security measure. And then there's this: stackoverflow.com/questions/8231048/…