Commit d8e84cf
committed
fix(framework): improve themeRoot validation (#13354)
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 behavior1 parent d5a574c commit d8e84cf
3 files changed
Lines changed: 52 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | | - | |
| 158 | + | |
160 | 159 | | |
161 | 160 | | |
162 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 46 | | |
52 | 47 | | |
53 | 48 | | |
54 | | - | |
55 | | - | |
| 49 | + | |
| 50 | + | |
56 | 51 | | |
57 | 52 | | |
58 | 53 | | |
| |||
62 | 57 | | |
63 | 58 | | |
64 | 59 | | |
65 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
1 | 11 | | |
2 | 12 | | |
3 | 13 | | |
4 | 14 | | |
5 | 15 | | |
6 | 16 | | |
7 | 17 | | |
8 | | - | |
9 | | - | |
| 18 | + | |
| 19 | + | |
10 | 20 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
15 | 25 | | |
16 | | - | |
17 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
18 | 31 | | |
19 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
20 | 35 | | |
21 | 36 | | |
22 | 37 | | |
23 | 38 | | |
| 39 | + | |
24 | 40 | | |
25 | 41 | | |
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
29 | 45 | | |
30 | 46 | | |
31 | | - | |
| 47 | + | |
| 48 | + | |
32 | 49 | | |
33 | 50 | | |
34 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
35 | 56 | | |
36 | | - | |
| 57 | + | |
37 | 58 | | |
38 | 59 | | |
39 | 60 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 61 | + | |
| 62 | + | |
43 | 63 | | |
44 | 64 | | |
45 | 65 | | |
| |||
50 | 70 | | |
51 | 71 | | |
52 | 72 | | |
| 73 | + | |
53 | 74 | | |
54 | 75 | | |
55 | 76 | | |
| |||
0 commit comments