Skip to content

red: the wasm import audit flags a module that imports fetch (VW1-21 canary) - #734

Closed
DrunkOnJava wants to merge 1 commit into
mainfrom
red/vw1-21-canary
Closed

DrunkOnJava wants to merge 1 commit into
mainfrom
red/vw1-21-canary

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Red draft, not for merging. It adds a canary to viewer/tests/wasm-no-network-imports.spec.ts: a module that imports ./rvt_bg.js.__wbg_fetch_0, run through the same wasm-objdump -j Import -x and quoted pattern as the audit. The audit is expected to miss it, because wabt prints imports without quotes (src/binary-reader-objdump.cc:1607). Deploy viewer's browser tests record the failure, and the fix follows on its own branch.


Note

Low Risk
Test-only change to the viewer Playwright suite; no runtime or packaging behavior is modified.

Overview
Adds a canary test to wasm-no-network-imports.spec.ts so the VW1-21 compile-time import audit is exercised against a known-bad module, not only rvt_bg.wasm.

A small moduleImporting helper builds minimal WASM bytes that import named functions from ./rvt_bg.js (matching wasm-bindgen’s glue module path). The new test writes a temp canary.wasm that imports __wbg_fetch_0, runs the same wasm-objdump -j Import -x flow and NETWORK_IMPORT_RE filter as the main audit, and asserts the audit does not miss that import.

This is intended as a red draft: it should fail until the audit regex (or matching logic) accounts for how wabt prints import names without the quoted "fetch" form the current pattern expects.

Reviewed by Cursor Bugbot for commit c8612d5. Configure here.

… (VW1-21 canary)

Red draft: the failing output is added when this is rebuilt on its branch.
@DrunkOnJava

Copy link
Copy Markdown
Owner Author

Red draft done: the canary's failure (run 37379307824) is in the test commit of the pull request that fixes the audit.

@DrunkOnJava

Copy link
Copy Markdown
Owner Author

The fix is #735.

DrunkOnJava added a commit that referenced this pull request Oct 18, 2026
… (VW1-21 canary)

A canary for the VW1-21 audit: a module importing `./rvt_bg.js.__wbg_fetch_0`
(wasm-bindgen names a binding of fetch `__wbg_fetch_<hash>`), run through the
audit's own `wasm-objdump -j Import -x` and quoted pattern. An audit that
misses it cannot fail on the real wasm either.

Red on draft #734, Deploy viewer run 37379307824 (job 111996809427):

  ✘  14 [chromium] › tests/wasm-no-network-imports.spec.ts:57:1 › the import audit flags a module that imports fetch (VW1-21 canary) (11ms)

    Error: the audit missed the canary's fetch import:

    canary.wasm:	file format wasm 0x1

    Section Details:

    Import[1]:
     - func[0] sig=0 <./rvt_bg.js.__wbg_fetch_0> <- ./rvt_bg.js.__wbg_fetch_0

    expect(received).not.toEqual(expected) // deep equality

    Expected: not []

  1 failed
  20 passed (2.4m)

wabt prints an import with no quotes, so the pattern
`"(fetch|XMLHttpRequest|WebSocket|EventSource|sendBeacon)"` never matches,
and the real-wasm test beside it passed (16ms) whatever the wasm imports.
DrunkOnJava added a commit that referenced this pull request Oct 18, 2026
…d can fail (VW1-21, C6) (#735)

The VW1-21 privacy audit, which checks that the viewer's wasm imports no network primitive, could never fail. This PR fixes it and finishes C6's deploy-viewer items.

**The defect.** Every copy of the audit grepped `wasm-objdump -j Import -x` for `"fetch"` and similar names, with the quotes. That covers deploy-viewer, publish.yml, the Playwright spec, `tools/check-local.sh` and `.cursor/install.sh`. wabt prints an import as ` <- module.field`, with no quotes (`src/binary-reader-objdump.cc:1607`), so none of those patterns can match.

**Red** on draft #734, Deploy viewer run 37379307824. The canary imports `./rvt_bg.js.__wbg_fetch_0`, and the old audit printed the import and still missed it:
```
 - func[0] sig=0 <./rvt_bg.js.__wbg_fetch_0> <- ./rvt_bg.js.__wbg_fetch_0
Error: the audit missed the canary's fetch import
```

**The fix:** `viewer/scripts/audit-wasm-imports.mjs`, which needs only Node, so the deploy no longer installs wabt.
- It reads the imports with `WebAssembly.Module.imports()` and checks each one twice:
  - **By name.** wasm-bindgen names a binding of `fetch` or `sendBeacon` `__wbg_fetch_<hash>` and so on.
  - **By the body of its shim in the glue.** A constructor only shows there: `new WebSocket(...)` imports as `__wbg_new_<hash>`.
- The glue's own `fetch()` of the `.wasm` file sits in its init function, outside every shim, so it is not flagged.
- The audit fails when:
  - the wasm or the glue is missing;
  - an import has no shim it can read;
  - its built-in canary isn't flagged as it should be.

**What it found.** I ran it on the deployed viewer's wasm and glue from Pages:
- all 52 imports read, and no network primitive among them;
- the canary is caught;
- with one `__wbg_new_` shim edited to `new WebSocket(...)`, the audit flags it.

**The spec change.** `viewer/tests/wasm-no-network-imports.spec.ts` now reads imports through the script, in its own commit.
- It keeps its assertion, that `hits` equals `[]`.
- It no longer skips when wabt is missing.
- It also fails on an unreadable shim, or when the wasm has no imports at all.
- The advisor approved this reader change, as the commit records.

**Other deploy-viewer items from C6**
- The pnpm store is cached with `cache: pnpm` keyed on `viewer/pnpm-lock.yaml`. setup-node's explicit `cache` takes precedence over `package-manager-cache` (src/main.ts:74).
- Playwright browsers are cached at `~/.cache/ms-playwright`, keyed on the Playwright version. The OS packages are still installed each run.
- When a browser test fails, `playwright-report/` and `test-results/` are uploaded and kept for 14 days.

The README, AGENTS.md, the privacy-posture and build-pipeline docs, viewer/README.md and the CHANGELOG now describe the new audit.
@DrunkOnJava
DrunkOnJava deleted the red/vw1-21-canary branch October 18, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant