Skip to content

Webview resources fail with 401 when the remote authority contains uppercase letters (e.g. WSL distro FedoraLinux-44) #341451

Closed as not planned

Description

@agilous

Does this issue occur when all extensions are disabled?: Not tested. Reproducing it needs the WSL extension plus an extension that opens a webview from the remote.

  • VS Code Version: 1.141.1 (stable, commit 7baac39), Windows desktop
  • OS Version: Windows 10.0.26300.9550
  • WSL: 3.0.3.0 (kernel 6.18.54.1-1), distro FedoraLinux-44 (Fedora Linux 44)
  • WSL extension: ms-vscode-remote.remote-wsl 0.104.3
  • Extension where it showed up: mhutchie.git-graph 1.30.0

Summary

When a window's remote authority contains uppercase letters, webviews from remote extensions can't load their local resources. Every resource request returns 401 and the webview stays blank.

With WSL, this happens when a folder is opened with code . from a distro whose name has capitals, which gives the remote authority wsl+FedoraLinux-44. The same folder opened with the lowercase authority wsl+fedoralinux-44 works.

Steps to reproduce

  1. Use a WSL distro with uppercase letters in its name, here FedoraLinux-44.
  2. In that distro, cd into a git repository and run code .. The window log records remoteAuthority=wsl+FedoraLinux-44.
  3. Open a webview from a remote extension that loads its scripts and styles through asWebviewUri and localResourceRoots, for example Git Graph: View Git Graph.
  4. The webview stays blank. The main window's DevTools console shows:
    out.min.css:1  Failed to load resource: the server responded with a status of 401 ()
    out.min.js:1  Failed to load resource: the server responded with a status of 401 ()
    
    The extension host never receives a message from the webview, because its script never loads.
  5. Close the window and reopen the same folder with a lowercase authority:
    code --folder-uri "vscode-remote://wsl+fedoralinux-44/home/<user>/<repo>"
    
    The webview now loads normally.

Expected: webview resources load whatever the case of the remote authority.

Cause

This comes from reading the shipped 1.141.1 bundle. Names below are de-minified approximations; the source files are src/vs/workbench/contrib/webview/browser/webviewElement.ts and resourceLoading.ts.

  1. The authority gets lowercased. Webview resource URIs carry the authority in a hostname: https://<scheme>+<encoded authority>.vscode-resource.vscode-cdn.net/.... The webview service worker rebuilds the authority from URL.hostname, which the browser always lowercases. So wsl+FedoraLinux-44 comes back as wsl+fedoralinux-44.
  2. WebviewElement.loadResource compares it case-sensitively. It only looks up the remote OS when the request's authority exactly equals the connection's:
    const remoteOS = uri.scheme === Schemas.vscodeRemote
        && this._remoteAgentService.getConnection()?.remoteAuthority === uri.authority
            ? (await this._remoteAgentService.getEnvironment())?.os
            : undefined;
  3. The mismatch becomes a 401. With remoteOS undefined, getResourceToLoad returns nothing for a vscode-remote URI (if (remoteOS === undefined) return;). loadLocalResource then logs Webview.loadLocalResource - access denied at trace level and returns AccessDenied. WebviewElement answers the service worker with status: 401.

The root check that follows (extUri.isEqualOrParent → isEqualAuthority) already ignores case. That makes the strict === in loadResource the one case-sensitive step.

Suggested fix: compare the authorities in loadResource with isEqualAuthority, or otherwise ignore case.

Workaround: open WSL folders with a lowercase authority, either with code --folder-uri "vscode-remote://wsl+<distro-lowercase>/<path>" or from File → Open Recent.

Metadata

Metadata

Labels

WSLbugregressionwebview

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions