diff --git a/gateway-applications/src/main/resources/applications/knoxauth/app/login.html b/gateway-applications/src/main/resources/applications/knoxauth/app/login.html index 8c69ec9c20..6a30f61065 100644 --- a/gateway-applications/src/main/resources/applications/knoxauth/app/login.html +++ b/gateway-applications/src/main/resources/applications/knoxauth/app/login.html @@ -36,40 +36,86 @@ diff --git a/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/DEPLOYMENT.md b/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/DEPLOYMENT.md index 220c3177a6..e746fdd331 100644 --- a/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/DEPLOYMENT.md +++ b/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/DEPLOYMENT.md @@ -332,7 +332,18 @@ Organizations with branding requirements or compliance needs should use `KNOX_TH ### Theme Name Validation -The theme loader only loads files from `styles/themes/THEME_NAME/theme.css`. Path traversal attacks (e.g., `?theme=../../etc/passwd`) are prevented by the URL structure. +The `?theme=` parameter and the saved localStorage preference are attacker-influenceable, +so the theme loader validates every candidate against `^[a-zA-Z0-9_-]{1,64}$` before it is +stored or used. This rejects quotes, angle brackets, dots and path separators, which +blocks both markup injection and path traversal (e.g. `?theme=../../etc/passwd`). +Validation is applied to values read back from localStorage as well as to the URL +parameter, so a value saved by an earlier visit cannot bypass it, and the stylesheet +element is built with DOM APIs rather than string concatenation. + +Because the only URL the loader can produce is `styles/themes/THEME_NAME/theme.css`, the +themes actually installed on the server are the effective allowlist. A name that does not +match an installed theme fails to load, the base Knox styles remain in effect, and the +saved preference is discarded. ### Content Security Policy @@ -340,6 +351,11 @@ If you have strict CSP, ensure it allows: - Loading CSS from same origin - Loading fonts from Google Fonts (if using modern theme) +A policy can be applied to the knoxauth route with the WebAppSec provider's +`SecurityHeaderFilter`, which emits arbitrary response headers from its init +parameters. Note that `login.html` currently uses inline scripts and inline event +handlers, so a policy for this page needs `'unsafe-inline'` for `script-src`. + Example CSP: ``` Content-Security-Policy: style-src 'self' https://fonts.googleapis.com; diff --git a/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/README.md b/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/README.md index e15aa77214..4bbfd58725 100644 --- a/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/README.md +++ b/gateway-applications/src/main/resources/applications/knoxauth/app/styles/themes/README.md @@ -441,9 +441,18 @@ Modern CSS features used: ## Security Considerations -1. **XSS Protection**: Theme names are not executed as code, only used to construct file paths -2. **Path Traversal**: Theme loader only loads files from `styles/themes/` directory -3. **Content Security Policy**: Ensure CSP allows loading external fonts if using Google Fonts +1. **Theme Name Validation**: Theme names arrive from untrusted sources (the `?theme=` + URL parameter and the saved localStorage preference), so each candidate must match + `^[a-zA-Z0-9_-]{1,64}$` before it is stored or used. Validation is applied on the + localStorage read path as well as the URL, and a value that fails is discarded. +2. **XSS Protection**: The stylesheet element is created with DOM APIs + (`document.createElement`) rather than by concatenating markup, so a theme name can + never be parsed as HTML. +3. **Path Traversal**: The validation pattern rejects dots and path separators, so the + only URL the loader can produce is `styles/themes/THEME_NAME/theme.css`. A name that + does not correspond to an installed theme simply fails to load and the base styles + remain in effect - the themes present on the server are the effective allowlist. +4. **Content Security Policy**: Ensure CSP allows loading external fonts if using Google Fonts ## Troubleshooting