-
Notifications
You must be signed in to change notification settings - Fork 0
Fix typos in index.html #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| form.addEventListener('submit', (ev) => { | ||
| ev.preventDefault(); | ||
| const q = document.getElementById('input').value; | ||
| document.getElementById('out').innerHTML = q; |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To prevent DOM-based XSS, you should never assign untrusted user input directly to innerHTML. Instead, use a method that treats the input as plain text. In the case of this example, replacing innerHTML with either textContent or ensuring output is properly escaped before assignment is safest.
The best way to fix this specific issue:
- Change line 23 from
document.getElementById('out').innerHTML = q;todocument.getElementById('out').textContent = q;.
This change ensures that any characters in q with HTML significance (such as <, >, &) will be rendered as text, not interpreted as markup or script.
No new imports or library dependencies are required for this fix.
-
Copy modified line R23
| @@ -20,7 +20,7 @@ | ||
| form.addEventListener('submit', (ev) => { | ||
| ev.preventDefault(); | ||
| const q = document.getElementById('input').value; | ||
| document.getElementById('out').innerHTML = q; | ||
| document.getElementById('out').textContent = q; | ||
| }); | ||
| </script> | ||
| </body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new HTML test page designed to demonstrate XSS (Cross-Site Scripting) vulnerabilities for local testing purposes. The page contains a form that accepts user input and directly outputs it to the DOM without sanitization.
- Adds a complete HTML page with form input and JavaScript handling
- Implements vulnerable XSS behavior by directly inserting user input into innerHTML
- Includes basic form structure with submit handling and DOM manipulation
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| <title>Vulnerable XSS Test Page (Local test)</title> | ||
| </head> | ||
| <body> | ||
| <h1>Vulnerable Testt</h1> |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the heading text. 'Testt' should be 'Test'.
| <h1>Vulnerable Testt</h1> | |
| <h1>Vulnerable Test</h1> |
| const form = document.getElementById('f'); | ||
| form.addEventListener('submit', (ev) => { | ||
| ev.preventDefault(); | ||
| const q = document.getElementById('input').value; |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is vulnerable to XSS attacks as it directly inserts user input into innerHTML without sanitization. For a test page demonstrating vulnerabilities, this is intentional, but consider adding a comment explaining this is the vulnerable behavior being demonstrated.
| const q = document.getElementById('input').value; | |
| const q = document.getElementById('input').value; | |
| // WARNING: This is intentionally vulnerable code for XSS demonstration purposes. | |
| // Do NOT use this pattern in production. Always sanitize user input before inserting into innerHTML. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <title>Vulnerable XSS Test Page (Local test)</title> | ||
| </head> | ||
| <body> | ||
| <h1>Vulnerable Testt</h1> |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word "Testt" contains a spelling error with an extra 't' at the end. It should be "Test".
| <h1>Vulnerable Testt</h1> | |
| <h1>Vulnerable Test</h1> |
| form.addEventListener('submit', (ev) => { | ||
| ev.preventDefault(); | ||
| const q = document.getElementById('input').value; | ||
| document.getElementById('out').innerHTML = q; |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is vulnerable to Cross-Site Scripting (XSS) attacks. User input is directly inserted into the DOM via innerHTML without any sanitization. An attacker could inject malicious scripts by entering HTML/JavaScript code. Use textContent instead of innerHTML, or implement proper input sanitization if HTML content is genuinely needed.
| document.getElementById('out').innerHTML = q; | |
| document.getElementById('out').textContent = q; |
No description provided.