Commit 4c4d717
authored
feat(IDE-1701): settings page auth flow — bridge persist and forward apiUrl (#453)
* feat: inject __ideExecuteCommand__ bridge in settings page and bump protocol version to 25 [IDE-1701]
Replace __ideLogin__/__ideLogout__ COM methods with a generic
__ideExecuteCommand__ bridge that dispatches any LS command with
callback support via window.__ideCallbacks__. Bump ProtocolVersion to 25.
* refactor: extract ExecuteCommandBridge to shared class for webview reuse [IDE-1701]
Move BuildClientScript() and DispatchAsync() into a standalone ExecuteCommandBridge
class. HtmlSettingsScriptingBridge delegates dispatch and HtmlSettingsWindow
uses BuildClientScript() for injection, enabling any future WebBrowser panel
(e.g. tree view) to reuse the same bridge.
* feat(IDE-1701): save login args from settings page and remove persist flag
- Remove persist flag from OnHasAuthenticated — always saves endpoint + token
- Keep Save(options, false) to avoid DidChangeConfigurationAsync loop
- Keep isNewLogin guard — only triggers HandleAuthenticationSuccess on first login
- Keep UpdateAuthToken(token, apiUrl) — settings page webview always updated
- Add bridge persist in HtmlSettingsScriptingBridge.__ideExecuteCommand__: when
snyk.login called with 3+ args, save authMethod/endpoint/ignoreUnknownCA to
options properties directly (no Save() call → no SettingsChanged event →
no DidChangeConfigurationAsync to LS)
- Remove OnHasAuthenticated_NoPersist test; rename persist-prefixed tests
- Add HtmlSettingsScriptingBridgeTest with 6 tests for login args persist
* feat(IDE-1701): forward apiUrl in UpdateAuthToken for settings page webview
Pass apiUrl alongside token when calling window.setAuthToken via InvokeSetAuthToken
so the settings page can update both the token and apiUrl fields after auth.
* fix(IDE-1701): apply auth webview bridge security patterns
- Add callbackId XSS allowlist guard (regex ^(__cb_\d+)?$) in ExecuteCommandBridge.IsValidCallbackId, used in DispatchAsync and InvokeCommandCallback
- Fix JS string escaping order in InvokeSetAuthToken: escape backslash before single-quote
- Add volatile keyword to HtmlSettingsWindow singleton instance for cross-thread visibility
- Clear stored token when auth method changes in ParseAndSaveConfigAsync to prevent stale token from one method being used with another
- Add tests for all four fixes
* fix: add ExecuteCommandBridge.cs to csproj compile items [IDE-1701]
* fix: use ForContext(typeof) for static class logger [IDE-1701]
* fix: expose LogManager.ForContext(Type) as public for static class callers [IDE-1701]
* fix: add missing Language using in HtmlSettingsScriptingBridgeTest [IDE-1701]
* fix(IDE-1701): inject bridge script into HTML before NavigateToString
The LS HTML page checks window.__ideExecuteCommand__ during its own
initialization scripts. Injecting only in LoadCompleted (after the page
has already parsed and run its scripts) means the auth button is never
wired up, causing it to do nothing when clicked.
Now inject bridge functions directly into the HTML string before
NavigateToString so they are defined before any LS page scripts run.
The LoadCompleted injection is kept as a secondary safety net.
* security: restrict webview executeCommand bridge to snyk.* namespace
Prevents XSS-to-arbitrary-command escalation by rejecting any command
not prefixed with "snyk." before it reaches the Language Server.
* fix: address PR review feedback for executeCommand bridge
- Extract <head> tag string to constant in InjectBridgeScriptIntoHtml
- Move callbackId validation outside ThreadHelper.Run in InvokeCommandCallback
- Extract JS string escaping into ExecuteCommandBridge.EscapeForJsString utility
- Add _cb_8 and whitespace test cases for IsValidCallbackId
- Add test for default OAuth fallback on invalid auth method string1 parent 83032e5 commit 4c4d717
19 files changed
Lines changed: 612 additions & 124 deletions
File tree
- Snyk.VisualStudio.Extension.2022
- Language
- Settings
- UI/Html
- Snyk.VisualStudio.Extension.Tests
- Language
- Settings
- UI/Html
- Tests/Integration.Tests
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
365 | 375 | | |
366 | 376 | | |
367 | 377 | | |
| |||
Lines changed: 15 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
273 | 278 | | |
274 | 279 | | |
275 | 280 | | |
276 | 281 | | |
277 | 282 | | |
278 | 283 | | |
279 | | - | |
280 | 284 | | |
281 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
282 | 293 | | |
283 | | - | |
284 | | - | |
| 294 | + | |
285 | 295 | | |
286 | 296 | | |
287 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
Lines changed: 76 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | | - | |
| 117 | + | |
| 118 | + | |
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| |||
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
172 | 201 | | |
173 | | - | |
| 202 | + | |
| 203 | + | |
174 | 204 | | |
175 | 205 | | |
176 | 206 | | |
| |||
179 | 209 | | |
180 | 210 | | |
181 | 211 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | 212 | | |
202 | 213 | | |
203 | | - | |
| 214 | + | |
204 | 215 | | |
205 | 216 | | |
206 | 217 | | |
| |||
259 | 270 | | |
260 | 271 | | |
261 | 272 | | |
262 | | - | |
| 273 | + | |
263 | 274 | | |
264 | 275 | | |
265 | 276 | | |
| |||
269 | 280 | | |
270 | 281 | | |
271 | 282 | | |
272 | | - | |
| 283 | + | |
273 | 284 | | |
274 | 285 | | |
275 | 286 | | |
| |||
279 | 290 | | |
280 | 291 | | |
281 | 292 | | |
282 | | - | |
| 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 | + | |
283 | 329 | | |
284 | 330 | | |
285 | 331 | | |
| |||
291 | 337 | | |
292 | 338 | | |
293 | 339 | | |
294 | | - | |
| 340 | + | |
| 341 | + | |
295 | 342 | | |
296 | 343 | | |
297 | 344 | | |
298 | | - | |
| 345 | + | |
299 | 346 | | |
300 | 347 | | |
301 | 348 | | |
| |||
307 | 354 | | |
308 | 355 | | |
309 | 356 | | |
310 | | - | |
| 357 | + | |
311 | 358 | | |
312 | 359 | | |
313 | 360 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
| |||
Lines changed: 121 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
0 commit comments