Skip to content

fix(webview): assetUri keeps .. segments, so a computed path can escape out/webview #286

Description

@eFAILution

Follow-up from #275.

Problem

src/webview/webviewHtml.ts:40:

const parts = relativePath.split('/').filter(Boolean);
return webview.asWebviewUri(
  vscode.Uri.joinPath(extensionUri, 'out', 'webview', ...parts)
);

filter(Boolean) drops empty segments but keeps .., so assetUri(webview, extensionUri, '../extension.js') resolves outside the out/webview root the doc comment promises. An empty relativePath silently returns the directory itself rather than failing.

Unreachable today — the only call site passes the literal 'styles/loading.css'. It matters because the point of the module is that future callers pass computed paths, and the next PRs in the #275 sequence are exactly those callers.

Suggested fix

Reject a path that contains a .. segment, starts from the filesystem root, or yields no segments at all. Throw rather than return a URI: a bad asset path is a programming error, and a silently wrong URI just 404s inside the webview with nothing pointing back here.

Covered by the unit tests this module gains once it is vscode-free.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions