Skip to content
Open
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 @@ -38,3 +38,8 @@
**Vulnerability:** Missing input validation on `setLanguage()` could allow invalid strings (like Prototype Pollution payloads or arbitrary text) to be applied to the DOM (`lang` attribute) and stored in `localStorage`.
**Learning:** The global `setLanguage` function assumed inputs would only come from predefined button clicks, skipping runtime validation.
**Prevention:** Always sanitize and validate function arguments at the application boundary, even if the primary caller is trusted, to enforce defense in depth.

## 2025-02-12 - [Strict CSP on Main Page]
**Vulnerability:** The main `index.html` used a permissive `default-src 'self'` CSP and `base-uri 'self'`, which is weaker than a strict deny-by-default approach.
**Learning:** Even static HTML sites should use a strict deny-by-default CSP (`default-src 'none'`) and explicitly allow only necessary asset types (`script-src`, `style-src`, etc.) to minimize attack surface in case of future changes or vulnerabilities. `base-uri 'none'` and `object-src 'none'` are also crucial.
**Prevention:** Always default to a strict `default-src 'none'` CSP for all HTML entry points, explicitly declaring necessary sources.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- **๋ณด์•ˆ ๊ฐœ์„ **: `i18n.js`์˜ `setLanguage()` ํ•จ์ˆ˜์— ํ—ˆ์šฉ๋œ ์–ธ์–ด์ธ์ง€ ํ™•์ธํ•˜๋Š” ์ž…๋ ฅ๊ฐ’ ๊ฒ€์ฆ(Input Validation) ๋กœ์ง์„ ์ถ”๊ฐ€ํ•˜์—ฌ Prototype Pollution ๋ฐ ์œ ํšจํ•˜์ง€ ์•Š์€ ์ƒํƒœ ์ฃผ์ž…์„ ๋ฐฉ์ง€ํ–ˆ์Šต๋‹ˆ๋‹ค.
- **์„ฑ๋Šฅ ๊ฐœ์„ **: `i18n.js`์—์„œ ์ดˆ๊ธฐ ๋กœ๋“œ ์‹œ ๊ธฐ๋ณธ ์–ธ์–ด๊ฐ€ ํ•œ๊ตญ์–ด(ko)์ธ ๊ฒฝ์šฐ ๋ถˆํ•„์š”ํ•œ DOM ์ˆœํšŒ ๋ฐ ํ…์ŠคํŠธ ์—…๋ฐ์ดํŠธ๋ฅผ ์ƒ๋žตํ•˜๋„๋ก ๊ฐœ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.
- **ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€**: ๋‹ค๊ตญ์–ด ์ฒ˜๋ฆฌ ๋กœ์ง์˜ ๋ฌด๊ฒฐ์„ฑ์„ ๊ฒ€์ฆํ•˜๊ธฐ ์œ„ํ•ด `test_i18n.html` ํ…Œ์ŠคํŠธ ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
- **๋ณด์•ˆ ๊ฐœ์„ **: ๋ฉ”์ธ ํŽ˜์ด์ง€(`index.html`)์˜ Content-Security-Policy๋ฅผ `default-src 'none'` ๊ธฐ๋ฐ˜์˜ ์—„๊ฒฉํ•œ ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ ๋ฐฉ์‹์œผ๋กœ ๊ฐ•ํ™”ํ•˜์—ฌ ์ž ์žฌ์ ์ธ ๊ณต๊ฒฉ ํ‘œ๋ฉด์„ ์ตœ์†Œํ™”ํ–ˆ์Šต๋‹ˆ๋‹ค.
2 changes: 1 addition & 1 deletion 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">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self'; object-src 'none'; base-uri 'self'; form-action 'none'; upgrade-insecure-requests; require-trusted-types-for 'script';">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-src 'none'; upgrade-insecure-requests; require-trusted-types-for 'script';">
<meta name="referrer" content="strict-origin-when-cross-origin">
<title>๋งฅ๋ฝ์ง€ํ˜œ ์—ฐ๊ตฌ์‹ค | Contextual Wisdom Lab</title>
<meta
Expand Down
62 changes: 62 additions & 0 deletions tests/test_index_security.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Security regression tests for the main page (index.html)."""

import re
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
INDEX = ROOT / "index.html"


def _index_html() -> str:
"""Return the main index.html source."""
return INDEX.read_text(encoding="utf-8")


def _csp_content(html: str) -> str:
"""Extract the CSP meta policy from the HTML."""
match = re.search(
r'<meta\s+http-equiv="Content-Security-Policy"\s+content="([^"]+)"',
html,
)
assert match is not None, "index.html must declare a CSP meta policy"
return match.group(1)


def test_index_declares_strict_csp() -> None:
"""The main page limits active content using a strict deny-by-default CSP."""
policy = _csp_content(_index_html())

for directive in (
"default-src 'none'",
"script-src 'self'",
"img-src 'self'",
"font-src 'self'",
"connect-src 'self'",
"object-src 'none'",
"base-uri 'none'",
"form-action 'none'",
"frame-src 'none'",
"upgrade-insecure-requests",
"require-trusted-types-for 'script'",
"style-src 'self'",
):
assert directive in policy
assert "'unsafe-inline'" not in policy
assert "'unsafe-eval'" not in policy

def test_index_has_no_inline_active_content() -> None:
"""Strict CSP remains enforceable without inline script or style exceptions."""
html = _index_html()

assert re.search(r"<style(?:\s|>)", html, flags=re.IGNORECASE) is None
assert re.search(r"\sstyle\s*=", html, flags=re.IGNORECASE) is None
assert re.search(
r"<script(?![^>]*\bsrc=)[^>]*>", html, flags=re.IGNORECASE
) is None
assert re.search(r"\son[a-z]+\s*=", html, flags=re.IGNORECASE) is None
assert 'href="styles.css"' in html
assert 'src="i18n.js"' in html
assert (
'<meta name="referrer" content="strict-origin-when-cross-origin">' in html
)
Loading