Commit 8705190
fix: preserve branch info and extract factory parameters correctly
Fixes #23666
PROBLEM:
--------
1. Branch was not taken into account when creating workspace with editor definition
Example: https://github.com/user/repo/tree/feature?che-editor=che-code
Result: workspace created from 'main' instead of 'feature'
2. Factory and override parameters were removed from URL but not passed to backend
Example: https://github.com/user/repo?override.devfileFilename=custom.yaml
Result: devfile filename override was lost
ROOT CAUSE:
-----------
Factory parameters in query string prevented backend from correctly parsing
branch information, and removed parameters were not extracted to overrideParams.
SOLUTION:
---------
Comprehensive URL sanitization with parameter extraction:
1. sanitizeUrlForFactoryResolver()
- Returns { sanitizedUrl, extractedOverrideParams }
- Extracts PROPAGATE_FACTORY_ATTRS to overrideParams
- Extracts override.* parameters to overrideParams
- Preserves branch info in URL path (/tree/branch)
- For Azure DevOps: keeps version/path in URL AND extracts them
- For SSH: extracts ALL params to overrideParams
2. getRepoFromLocation()
- Extracts base repository URL without branches
- Used for trusted sources comparison
- Ensures any branch of trusted repo is recognized
3. factoryApi.ts
- Uses sanitizeUrlForFactoryResolver()
- Merges extracted params with existing overrideParams
- Sends clean URL and complete overrideParams to backend
BEHAVIOR EXAMPLES:
------------------
HTTP with override params:
Input: https://github.com/user/repo?override.devfileFilename=custom.yaml&che-editor=che-code
URL: https://github.com/user/repo
Params: { 'override.devfileFilename': 'custom.yaml', 'che-editor': 'che-code' }
HTTP with branch:
Input: https://github.com/user/repo/tree/feature?che-editor=che-code
URL: https://github.com/user/repo/tree/feature
Params: { 'che-editor': 'che-code' }
Azure DevOps (provider-specific params preserved):
Input: https://dev.azure.com/org/proj/_git/repo?version=GBmain&che-editor=che-code
URL: https://dev.azure.com/org/proj/_git/repo?version=GBmain
Params: { 'version': 'GBmain', 'che-editor': 'che-code' }
SSH (all params extracted):
Input: git@github.com:user/repo.git?revision=main&override.devfileFilename=custom.yaml
URL: git@github.com:user/repo.git
Params: { 'revision': 'main', 'override.devfileFilename': 'custom.yaml' }
SECURITY FIX:
-------------
Implemented robust Azure DevOps domain detection using allowlist approach
to prevent URL spoofing attacks (GitHub Advanced Security alert).
isAzureDevOpsHost() with strict validation:
- Exact match: dev.azure.com
- Subdomain match: *.azure.com (requires >=3 parts, e.g., myorg.azure.com)
- Legacy support: *.visualstudio.com (requires >=3 parts)
- Blocks: azure.com alone, evil.azure.com.attacker.com, attacker.com/azure.com
TESTING:
--------
✅ 88 tests for sanitizeUrlForFactoryResolver (includes new merging tests)
✅ 45 tests for getRepoFromLocation (includes security tests)
✅ 14 tests for factoryApi (updated for new behavior)
✅ 2274 total tests pass
✅ 215 snapshots pass
✅ All linting checks pass
NEW FILES:
----------
- sanitizeUrlForFactoryResolver.ts (returns object with URL and params)
- sanitizeUrlForFactoryResolver.spec.ts (88 tests)
- getRepoFromLocation.ts (base repo extraction)
- getRepoFromLocation.spec.ts (45 tests)
- sanitizeLocation.ts (simple factory param removal)
- sanitizeLocation.spec.ts (10 tests)
MODIFIED FILES:
---------------
- factoryApi.ts (uses new sanitization, merges params)
- factoryApi.spec.ts (updated for extraction behavior)
- helpers.ts (isTrustedRepo with getRepoFromLocation)
- helpers.spec.ts (new tests for factory params)
- UntrustedSourceModal/index.tsx (saves base repo only)
Co-authored-by: GitHub Advanced Security <security@github.com>
Signed-off-by: Oleksii Orel <oorel@redhat.com>1 parent c6810b3 commit 8705190
File tree
15 files changed
+1578
-265
lines changed- packages/dashboard-frontend/src
- components/UntrustedSourceModal
- pages/GetStarted/SamplesList
- __tests__
- services
- backend-client
- __tests__
- helpers/factoryFlow
- __tests__
- registry
- __tests__
- store/Workspaces/Preferences
- __tests__
15 files changed
+1578
-265
lines changedLines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
114 | | - | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
167 | 171 | | |
168 | 172 | | |
169 | 173 | | |
| |||
Lines changed: 0 additions & 90 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | 242 | | |
333 | 243 | | |
334 | 244 | | |
| |||
Lines changed: 2 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 100 | + | |
113 | 101 | | |
114 | | - | |
| 102 | + | |
115 | 103 | | |
116 | 104 | | |
117 | 105 | | |
| |||
Lines changed: 37 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | | - | |
| 89 | + | |
| 90 | + | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | | - | |
| 95 | + | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
| |||
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
101 | 108 | | |
102 | | - | |
| 109 | + | |
103 | 110 | | |
| 111 | + | |
104 | 112 | | |
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
110 | | - | |
| 118 | + | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
| |||
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | | - | |
| 129 | + | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
129 | | - | |
| 137 | + | |
130 | 138 | | |
131 | 139 | | |
132 | 140 | | |
| |||
136 | 144 | | |
137 | 145 | | |
138 | 146 | | |
139 | | - | |
| 147 | + | |
140 | 148 | | |
141 | 149 | | |
142 | 150 | | |
| |||
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
149 | | - | |
| 157 | + | |
150 | 158 | | |
151 | 159 | | |
152 | 160 | | |
| |||
156 | 164 | | |
157 | 165 | | |
158 | 166 | | |
| 167 | + | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
| |||
179 | 188 | | |
180 | 189 | | |
181 | 190 | | |
182 | | - | |
| 191 | + | |
183 | 192 | | |
184 | 193 | | |
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
188 | 197 | | |
| 198 | + | |
189 | 199 | | |
190 | 200 | | |
191 | 201 | | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
195 | 205 | | |
196 | | - | |
| 206 | + | |
197 | 207 | | |
198 | 208 | | |
199 | 209 | | |
| |||
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
207 | | - | |
| 217 | + | |
208 | 218 | | |
209 | 219 | | |
210 | | - | |
211 | | - | |
212 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
213 | 223 | | |
214 | 224 | | |
215 | 225 | | |
216 | 226 | | |
217 | | - | |
| 227 | + | |
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
| |||
224 | 234 | | |
225 | 235 | | |
226 | 236 | | |
227 | | - | |
| 237 | + | |
228 | 238 | | |
229 | 239 | | |
230 | 240 | | |
| |||
235 | 245 | | |
236 | 246 | | |
237 | 247 | | |
238 | | - | |
| 248 | + | |
239 | 249 | | |
240 | 250 | | |
241 | 251 | | |
242 | 252 | | |
243 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
244 | 257 | | |
| 258 | + | |
245 | 259 | | |
246 | 260 | | |
247 | | - | |
248 | | - | |
| 261 | + | |
| 262 | + | |
249 | 263 | | |
250 | 264 | | |
251 | 265 | | |
| |||
Lines changed: 11 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
42 | 36 | | |
43 | 37 | | |
44 | | - | |
| 38 | + | |
45 | 39 | | |
46 | 40 | | |
47 | 41 | | |
| |||
0 commit comments