Skip to content

cowork: fix preview temp-file leak, crypto webview nonces, detect-format normalization - #14

Open
github-actions[bot] wants to merge 2 commits into
masterfrom
cowork/improve-vscode-schemaforge
Open

cowork: fix preview temp-file leak, crypto webview nonces, detect-format normalization#14
github-actions[bot] wants to merge 2 commits into
masterfrom
cowork/improve-vscode-schemaforge

Conversation

@github-actions

@github-actionsgithub-actionsBot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

One coherent correctness + hardening round on the preview/convert pipeline (commit a02c8a1).

Fixed (correctness bugs)

  • Temp-file leak: the schemaforge.previewEditor custom editor wrote a schemaforge_preview_<ts>.tmp into <installDir>/.temp on every render and save, and never deleted any of them. Scratch files now go through fs.promises.mkdtemp under os.tmpdir() and the directory is removed in a finally block.
  • Empty detection reached the CLI as an empty --from flag, failing opaquely. Convert now asks the user to pick the source format; QuickConvert and Diff abort with a clear message instead.

Hardened (security)

  • Webview CSP nonces were generated from predictable Math.random(); both preview surfaces now use crypto.randomBytes(16). Nonce generation and HTML escaping moved into one shared module (src/webview.ts) so the two implementations cannot drift again.

Changed (silent-failure / consistency)

  • normalizeFormat is applied to detected formats before they reach convert --from in QuickConvert, Diff and the .schemaforge editor (mixed-case/padded labels previously passed through verbatim in 3 of 5 call sites).
  • The provider reuses the canonical SCHEMA_FORMATS list instead of its own inline copy (the exact drift class src/formats.ts documents).
  • Removed unused execSchemaForgeSync, which silently swallowed CLI errors.

Tests

  • New functional tests for the shared webview helpers (nonce shape/uniqueness, escaping).
  • New source-level regression guards: temp files must use mkdtemp/os.tmpdir() with finally { rmSync } cleanup; no Math.random-based nonces; shared helper import required.
  • tsc -p . strict clean, eslint clean, 15/15 node --test pass.

…normalization
- schemaEditorProvider: temp scratch files now created via mkdtemp under
os.tmpdir() and removed in a finally block; previously every preview
render/save leaked a schemaforge_preview_*.tmp into <installDir>/.temp
- webview nonces: crypto.randomBytes instead of predictable Math.random;
getNonce/escapeHtml deduplicated into shared src/webview.ts so the two
preview surfaces cannot drift apart again
- detection robustness: normalizeFormat applied before convert --from in
quickConvert/diff/schemaEditorProvider; empty detection now asks the user
(convert) or aborts with a clear message (quickConvert/diff) instead of
passing an opaque empty --from to the CLI
- provider reuses canonical SCHEMA_FORMATS list (was an inline copy)
- removed unused execSchemaForgeSync which silently swallowed CLI errors
- tests: functional webview util tests + source-level regression guards for
temp lifecycle and nonce randomness; tsc strict clean, eslint clean,
15/15 node --test pass
@Coding-Dev-ToolsCoding-Dev-Tools changed the title cowork-bot: automated improvements (cowork/improve-vscode-schemaforge)cowork: fix preview temp-file leak, crypto webview nonces, detect-format normalizationAug 23, 2026
When schemaforge.cliPath points at a .cmd/.bat wrapper on Windows,
execFile runs with shell:true and Node flattens argv into one
'cmd.exe /c' line without quoting. A file path containing cmd
metacharacters (e.g. foo&calc.bat) could execute arbitrary commands.
- quote every argument in shell mode; reject metacharacter-bearing
arguments with a clear error before any process is spawned
- export quoteShellArg for testability; add source-level regression
tests locking the guard in
tsc strict clean, eslint clean, 17/17 tests pass.
Sign up for freeto 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

@cowork-bot