Client-Side XSS Exploitation
You are testing a modern single-page application (SPA) built with JavaScript. Traditional reflected XSS detection tools are not flagging vulnerabilities, but you suspect DOM-based XSS exists.
Application Details:
- URL: https://example.com/profile
- Framework: Custom JavaScript (no framework)
- Functionality: User profile page that displays user data from URL fragments
Code Snippet Found:
```javascript
function loadUserProfile() {
let userInput = window.location.hash.substring(1);
let profileDiv = document.getElementById('profile');
profileDiv.innerHTML = "Welcome, " + decodeURIComponent(userInput);
}
window.addEventListener('hashchange', loadUserProfile);
```
Your Task:
1. Analyze the code for DOM-based vulnerabilities
2. Craft exploitation payloads
3. Demonstrate impact
4. Recommend secure coding fixes