Skip to content

fix(framework): improve themeRoot validation#13354

Merged
nnaydenow merged 1 commit intomainfrom
theme-root-fix
Apr 2, 2026
Merged

fix(framework): improve themeRoot validation#13354
nnaydenow merged 1 commit intomainfrom
theme-root-fix

Conversation

@nnaydenow
Copy link
Copy Markdown
Contributor

@nnaydenow nnaydenow commented Apr 1, 2026

Fix themeRoot validation to require explicit origin allowlist via meta tag
and separate configuration storage from validated URL usage.

Problem:

  • themeRoot URLs were not properly validated for security
  • getThemeRoot() mixed raw configuration with validated URLs
  • Missing validation for relative paths and URL formats

Solution:

  1. Require meta tag for all themeRoot usage:

    • Comma-separated list of allowed origins
    • Wildcard "*" to allow any origin
    • Legacy "sap-allowedThemeOrigins" (camelCase) supported
    • Same-origin URLs allowed when meta tag present
  2. Separate configuration from validation:

    • getThemeRoot() returns raw configured value (unchanged)
    • validateThemeRoot() performs security checks and normalization
    • DOM link creation uses validated URL: {validatedRoot}/UI5/Base/baseLib/{theme}/css_variables.css
  3. Enhanced validation:

    • Absolute URLs: check origin against allowlist
    • Relative paths (./path, ../path): resolve to current origin
    • Absolute paths (/path): resolve to current origin
    • Add trailing slash if missing
    • Append /UI5/ to create proper theme asset path
    • Return undefined for invalid/unauthorized URLs
  4. Proper error handling:

    • Log warning when validation fails
    • No DOM link created for invalid themeRoot
    • Graceful fallback to default theme behavior

@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

ui5-webcomponents-bot commented Apr 1, 2026

🧹 Preview deployment cleaned up: https://pr-13354--ui5-webcomponents.netlify.app

@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 1, 2026 16:12 Inactive
@nnaydenow nnaydenow changed the title fix(framework): improve themeRoot validation and security fix(framework): improve themeRoot validation Apr 2, 2026
@nnaydenow nnaydenow merged commit ba4a08b into main Apr 2, 2026
21 of 22 checks passed
@nnaydenow nnaydenow deleted the theme-root-fix branch April 2, 2026 12:03
@ui5-webcomponents-bot ui5-webcomponents-bot temporarily deployed to preview April 2, 2026 12:04 Inactive
@ui5-webcomponents-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version v2.21.0 🎉

The release is available on v2.21.0

Your semantic-release bot 📦🚀

nnaydenow added a commit that referenced this pull request Apr 16, 2026
Fix themeRoot validation to require explicit origin allowlist via meta tag
and separate configuration storage from validated URL usage.

Problem:
- themeRoot URLs were not properly validated for security
- getThemeRoot() mixed raw configuration with validated URLs
- Missing validation for relative paths and URL formats

Solution:
1. Require meta tag for all themeRoot usage:
    <meta name="sap-allowed-theme-origins" content="https://cdn.example.com">

    - Comma-separated list of allowed origins
    - Wildcard "*" to allow any origin
    - Legacy "sap-allowedThemeOrigins" (camelCase) supported
    - Same-origin URLs allowed when meta tag present

2. Separate configuration from validation:
    - getThemeRoot() returns raw configured value (unchanged)
    - validateThemeRoot() performs security checks and normalization
    - DOM link creation uses validated URL: {validatedRoot}/UI5/Base/baseLib/{theme}/css_variables.css

3. Enhanced validation:
    - Absolute URLs: check origin against allowlist
    - Relative paths (./path, ../path): resolve to current origin
    - Absolute paths (/path): resolve to current origin
    - Add trailing slash if missing
    - Append /UI5/ to create proper theme asset path
    - Return undefined for invalid/unauthorized URLs

4. Proper error handling:
    - Log warning when validation fails
    - No DOM link created for invalid themeRoot
    - Graceful fallback to default theme behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants