Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
**Vulnerability:** Use of `innerHTML` for dynamic content and missing Content Security Policy (CSP).
**Learning:** Even if the content is currently static, using `innerHTML` is a dangerous pattern that can lead to XSS if the application grows. Prefer `textContent` and explicit DOM node creation.
**Prevention:** Establish a strong CSP and enforce secure DOM manipulation practices through documentation and code reviews.

## 2025-05-15 - CSP Hardening & Secure Event Handlers
**Vulnerability:** Weak CSP allowing form actions and reliance on inline property event handlers (`onclick`).
**Learning:** For static sites without forms, `form-action 'none'` provides defense-in-depth against unauthorized data exfiltration. Using `addEventListener` instead of `onclick` improves code clarity and follows modern security practices.
**Prevention:** Always set explicit button types and harden CSP directives like `form-action` and `base-uri` even if not immediately used. Use `addEventListener` for all dynamic elements.
9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'sha256-fgxmLOznNmVf4GAd24jy5Eiv/Rer+7sVLOBqnsVx0nY='; script-src 'self' 'sha256-cPRnZP+O4z5KsN+vdFstQwgKExGtoN98I3Gq+Tm1aSA='; object-src 'none'; base-uri 'self'; upgrade-insecure-requests;">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'sha256-fgxmLOznNmVf4GAd24jy5Eiv/Rer+7sVLOBqnsVx0nY='; script-src 'self' 'sha256-M6MErer+QDopN+Ivlj12GyByPCaRRGPWjKPHZVPjO+0='; object-src 'none'; base-uri 'self'; form-action 'none'; upgrade-insecure-requests;">
<meta name="referrer" content="no-referrer">
<title>5ive - UX Sample</title>
<style>
Expand Down Expand Up @@ -167,18 +167,21 @@ <h1>Welcome to 5ive</h1>
feedback.appendChild(content);

const closeBtn = document.createElement('button');
// βœ… Sentinel: Explicitly set type to prevent accidental form submission
closeBtn.type = 'button';
closeBtn.className = 'close-btn';
closeBtn.setAttribute('aria-label', 'Close notification');
closeBtn.textContent = 'Γ—';
closeBtn.onclick = () => {
// βœ… Sentinel: Use addEventListener instead of onclick for better security and flexibility
closeBtn.addEventListener('click', () => {
if (feedbackTimeout) clearTimeout(feedbackTimeout);
feedback.classList.remove('visible');
setTimeout(() => {
if (!feedback.classList.contains('visible')) {
feedback.textContent = '';
}
}, 300);
};
});
feedback.appendChild(closeBtn);

// Trigger reflow/transition
Expand Down