chore(webview): declare asset resource roots and unit-test the CSP helpers - #305
Merged
eFAILution merged 1 commit intoSep 21, 2026
Conversation
eFAILution
approved these changes
Sep 21, 2026
eFAILution
left a comment
Owner
There was a problem hiding this comment.
Approving. Closes #284, #285 and #286 exactly as they were written, and picks up a real bug on the way.
The empty localResourceRoots: [] on the detached panel is the one worth calling out — it permits no local files at all, so the identical document rendered from the Component Browser would have kept working while the hover path 404'd, which is the shape of bug that gets found late and blamed on the wrong change.
Verified:
createNoncealphabet is 64 characters, sobyte % 64divides 256 evenly and the bias is gone. The distribution test is the good kind — 2000 nonces, every character required to appear, max under 1.15x expected. It would fail on the old 62-character alphabet, which is what makes it worth having.assetUrithrows on empty,.and.., andASSET_ROOTis now the single place theout/webviewlayout is written down, shared withassetRoots.- All three panels declare
assetRoots(...): the detached one, the browser-path details panel, and the Component Browser.
438 passing, lint and types clean, CI green. Scoping the browser globals block to src/webview/client/** rather than all TypeScript is the right call — extension-host code touching document still gets flagged.
This was referenced Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
localResourceRoots: [], which permits no local files at all. The moment that panel's CSS or scripts move to files they would 404 — on that path only, while the identical document rendered from the Component Browser looked correct.vscode-free half ofwebviewHtml.tsintosrc/webview/csp.tsso the nonce and CSP helpers can be unit-tested, and closes two findings from the refactor(webview): serve loading-view CSS from linted external file under CSP #275 review while writing those tests.Change Type
Context
User-facing impact
GitLab scope
Affected areas
What changed by bucket
src/extension.ts,src/providers/componentBrowserProvider.ts,src/webview/webviewHtml.tsassetRoots(extensionUri)besideassetUri, which already owns theout/webviewlayout. All three panels use it: the detached panel replaceslocalResourceRoots: [], the browser-path details panel gains an explicit declaration instead of relying on the default, and the Component Browser drops its hand-written path.src/webview/csp.ts,src/webview/webviewHtml.tscreateNonceandcspMetaTagmove to avscode-free module, withcspMetaTag(cspSource, nonce)taking the origin as a string.webviewHtml.tskeepsassetUri/assetRootsand re-exports the pair, so callers still have one import.src/webview/csp.tssrc/webview/webviewHtml.tsassetUrirejects empty paths and./..segments, so a computed path cannot resolve outside the root its panel declares.esbuild.js.mapfile makes the webview fetch it, which the document'sdefault-src 'none'CSP blocks and reports — noise in the console that PRs 3-6 will be watching for real violations. Production builds emit no map either way.eslint.config.jssrc/webview/client/**/*.tswithglobals.browserplusacquireVsCodeApi. Scoped rather than applied to all TypeScript so extension-host code referencingdocumentorwindowis still flagged.tests/unit/csp.test.tsdefault-src 'none', nonce-gated scripts, no'unsafe-inline'on either directive).Validation
Local checks
npm run compilenpm test— 438 passing (+7 new);npm run lintcleanManual test notes
styles/loading.css.Breaking Changes
Risk and Rollback
assetUriguard could in principle reject a path that previously resolved, but its only caller passes the literalstyles/loading.css.Release Notes Draft
Checklist