GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: Electron security checklist の Tier 1 補完 (#204) by ymnao · Pull Request #210 · ymnao/scripta

Conversation

@ymnao

@ymnao ymnao commented Jun 21, 2026

Copy link
Copy Markdown
Owner

概要

undici の security advisory 9 件 (Dependabot alert #10-14, #17-20) を parent>child override で解消する。
@electron/get / jsdom 経由の 7.25.0 を ^7.28.0、node-gyp 経由の 6.25.0 を ^6.27.0 に固定。

関連 Issue

  • v0.5.0 milestone (chore: 旧 scripta からユニットテスト 60 ファイルを復元(PR B) #5)

移行 Stage

該当なし(security 対応)

変更内容

  • pnpm-workspace.yaml に 3 件の parent>child override を追加:
    • @electron/get>undici: ^7.28.0
    • jsdom>undici: ^7.28.0
    • node-gyp>undici: ^6.27.0
  • pnpm-lock.yaml を CI=true pnpm install --lockfile-only --no-frozen-lockfile で更新

対象 alert 9 件

# GHSA Severity 6.x/7.x Summary
10 GHSA-pr7r-676h-xcf6 medium 7.x cross-user information disclosure via shared cache whitespace bypass
11 GHSA-vmh5-mc38-953g high 7.x TLS certificate validation bypass via dropped requestTls in SOCKS5 ProxyAgent
12 GHSA-35p6-xmwp-9g52 low 6.x HTTP response queue poisoning via keep-alive socket reuse
13 GHSA-35p6-xmwp-9g52 low 7.x 同上
14 GHSA-hm92-r4w5-c3mj high 7.x cross-origin request routing via SOCKS5 proxy pool reuse
17 GHSA-p88m-4jfj-68fv medium 6.x HTTP header injection via Set-Cookie percent-decoding
18 GHSA-p88m-4jfj-68fv medium 7.x 同上
19 GHSA-g8m3-5g58-fq7m low 6.x Set-Cookie SameSite downgrade via permissive substring matching
20 GHSA-g8m3-5g58-fq7m low 7.x 同上

parent 特定

  • @electron/[email protected] (electron の devDep transitive) が optionalDep として undici: 7.25.0
  • [email protected] (Vitest の DOM 環境用 devDep) が undici: 7.25.0
  • [email protected] (@electron/rebuild → electron-builder 経由) が undici: 6.25.0

実害評価

いずれも build / test time の transitive で、本リポの runtime コード(main / preload / renderer)からは undici を直接利用しない。SOCKS5 ProxyAgent / shared HTTP cache / 攻撃者制御の Set-Cookie 等の前提を満たさないが、alert closed 化が目的で patch を適用。

動作確認

  • node_modules/.bin/biome check — pass (Found 2 infos = biome migrate suggestion のみ)
  • node_modules/.bin/tsc --noEmit — pass
  • node_modules/.bin/vitest run — 91 files / 2111 passed, 2 skipped
  • node_modules/.bin/electron-vite build — pass (~520ms)
  • CI (lint / typecheck / test / build / e2e / electron-e2e)
  • merge 後 alert Chore(deps): Bump marked from 18.0.2 to 18.0.3 #10-14, Stage 6: e2e テスト基盤(Playwright + window.api モック)を追加 #17-20 の 9 件すべて auto-close 確認

スクリーンショット

該当なし

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ymnao added 8 commits June 21, 2026 15:20
@ymnao
chore: Electron security checklist の Tier 1 補完 3 件 (#204)
918b59b
セッション 25 で検出された Electron Security Checklist 上の Tier 1
ギャップ 3 件を 1 PR でまとめて対応。

1. permission handler の明示 deny
   - electron/main/utils/permission-handler.ts を新設し、
     session.defaultSession に setPermissionRequestHandler /
     setPermissionCheckHandler を install
   - notifications / media / geolocation 等の web permission を
     handler 未登録時のデフォルトに暗黙依存せず常に false で返す
   - 将来 dependency が permission を要求しても穴が開かない設計

2. fs:read の 64MB サイズ上限
   - MAX_READ_FILE_BYTES (= 64 * 1024 * 1024) を fs.ts で集約
   - readFileImpl は読み込み前に fs.stat → 上限超で
     StructuredError("FILE_TOO_LARGE") を throw
   - 他 handler (OGP 100KB / git conflict 10MB) と上限思想を揃える
   - ErrorKind に FILE_TOO_LARGE を追加し、renderer 側
     translateError の日本語マッピングと NON_TRANSIENT_KINDS にも追従
   - test は sparse file (truncate) で stat.size のみ膨らませる方式で
     ディスク I/O ゼロ。境界 (==) も verify

3. SCRIPTA_PDF_DEBUG_HTML_PATH の本番 disable
   - pdf.ts の debug HTML 書き出しを is.dev ガードで囲む
   - packaged 本番では env が仕込まれても発火せず、path-guard を
     経由しない任意 path への書き込み裏口を塞ぐ
   - pdf.test.ts に dev=true / dev=false の両モードを verify する
     ケース追加 (@electron-toolkit/utils mock パターン)

closes #204
@ymnao
refactor: /simplify findings の cleanup 6 件
eec31ad
/simplify の 4 並列レビュー (Reuse / Simplification / Efficiency / Altitude) で
検出された 6 件を適用。挙動は不変、コードの簡潔さと一貫性のみを向上させる。

1. [Altitude] SCRIPTA_PDF_DEBUG にも is.dev guard を追加
   - 同種の dev-only debug env が pdf.ts に 2 つあり、SCRIPTA_PDF_DEBUG_HTML_PATH
     にだけ is.dev を入れていた。SCRIPTA_PDF_DEBUG の stderr 出力も dev 限定にし、
     packaged 本番に env を仕込まれても診断ログが漏れないようにする
   - これで本 PR の「env 経由の本番裏口を塞ぐ」スコープが網羅される

2. [Efficiency] readFileImpl を共有 FD に統合
   - fsp.stat + fsp.readFile は内部で open を 2 回するため、fs:read という
     hot path (タブ切替で多用) で syscall が半減できる
   - fsp.open → fh.stat → fh.readFile → close で同一 FD を共有
   - 副次効果として stat → read の TOCTOU race も構造的に消える

3. [Simplification] pdf.ts の二重ネストを flatten
   - `if (is.dev) { if (debugHtmlPath) { ... } }` を
     `const debugHtmlPath = is.dev ? ... : undefined; if (debugHtmlPath) { ... }`
     に書き換え、インデント 1 段削減

4. [Simplification] fs.test.ts に createSparseFile helper を抽出
   - 上限超 / 境界の 2 ケースで `open + truncate + close` の 6 行が重複
   - test-local helper に切り出して 1 行呼び出しに

5. [Simplification] boundary test の assertion 強化
   - `resolves.toBeTypeOf("string")` は「string 型である」だけで弱い
   - `resolves.toHaveLength(MAX_READ_FILE_BYTES)` で「ぴったり上限サイズ
     read できる」ことまで verify するよう変更

6. [Simplification] pdf.test.ts の mockIs.dev = false 重複削除
   - beforeEach + afterEach + test 内の 3 箇所で同じ reset をしていた
   - beforeEach の reset のみ残し、afterEach と test 内は削除(コメントで意図維持)

skip した findings:
- Reuse: pdf.test.ts と menu.test.ts の mockIs パターン共有
  → 2 ファイルのみで抽象化コスト > benefit
- Simplification: hoisted + beforeEach の二重初期化 → beforeEach reset は
  test isolation のため必要
- Simplification: permission-handler.test.ts の makeFakeSession 簡素化 →
  defensive null check は test helper として有用
- Altitude: 共通 io-limits.ts / readFileWithSizeCap helper → 第 2 caller が
  現れるまで premature factoring
- Altitude: FsError factory arity 統一 → 1 outlier は許容範囲
- Altitude: NON_TRANSIENT_KINDS をメタデータ化 → kind 数が一桁のうちは現状で OK
@ymnao
fix: #204 PR レビュー指摘 3 件への対応
f19c201
| # | 指摘 | 対応 |
|---|------|------|
| P1-1 | clipboard-read 全 deny で MarkdownEditor の「貼り付け」(navigator.clipboard.readText) が壊れる | installMainSessionPermissionHandlers を新設し clipboard-read / clipboard-sanitized-write を信頼 renderer origin に限り許可 |
| P1-2 | PDF 専用 session に permission handler 未設定 (任意 HTML を load する経路) | installPdfWebRequestFilter で installPermissionDenyHandlers(pdfSession) を呼ぶ |
| P2 | fs.ts:50 stat 後の追記で limit を超え得る | bounded read (cap = min(stat.size+1, MAX+1)) と total > stat.size 判定で stat 後の追記を検知して reject |

## 詳細

### P1-1: clipboard 許可を main session に限定して allowlist 化

permission-handler.ts を 2 関数に分割:

- installPermissionDenyHandlers: 全 web permission を deny (PDF 等の副 session 用)
- installMainSessionPermissionHandlers: clipboard-read / clipboard-sanitized-write
  を信頼 origin に限り許可、他は全 deny

origin 信頼判定は新規 electron/main/utils/renderer-url.ts に分離:
- dev: ELECTRON_RENDERER_URL の origin と一致するか
- prod: file: スキームかどうか

index.ts は installMainSessionPermissionHandlers を defaultSession に install。
これで MarkdownEditor のコンテキストメニュー「貼り付け / コピー / 切り取り」が
従前通り動作し、それ以外の permission (media / geolocation 等) は引き続き全 deny。

### P1-2: PDF 隔離 session に明示 deny

pdf.ts の installPdfWebRequestFilter で webRequest フィルタ install と同時に
installPermissionDenyHandlers(pdfSession) を呼ぶ。PDF 描画用 session は任意 HTML
を load し得るため main の clipboard 許可を継承させず、clipboard 含めて全 deny。

### P2: bounded read で stat 後の追記を検知

readFileImpl を以下の二段防御へ:
1. fh.stat() の申告サイズが MAX 超 → 即 reject (typical case の OOM 回避)
2. cap = min(stat.size+1, MAX+1) byte の bounded read で fh.read ループ。
   実 read bytes が stat 申告超 = stat 後の追記を検知して reject

これにより同一 FD でも inode の size がメタデータで動く件への defense in depth
が成立する。コメントの「TOCTOU 解消」表現は誤りだったので、stat 値だけは信用
しない旨を明記し直した。

### テスト

- renderer-url.test.ts (新規): isTrustedRendererOrigin の dev / prod
  両モードを cover
- permission-handler.test.ts: installPermissionDenyHandlers の全 deny に加え、
  installMainSessionPermissionHandlers の clipboard allowlist (trusted /
  untrusted origin / allowlist 外 permission / requestingUrl 欠落) を cover
- pdf.test.ts: PDF session の setPermission*Handler が install されることを verify

bounded read の「stat under-report」シナリオは ESM の fsp.open spy が複雑な割に
得るものが薄いため unit test 化を見送り、コード上のコメントで意図を残した。

unit test: 全 2137 pass / 2 skipped (regression なし)
@ymnao
fix: #204 PR 追加レビュー指摘 2 件への対応
7fdf532
| # | 指摘 | 対応 |
|---|------|------|
| P1 | permission-handler.test.ts の handler 型に null が含まれ pnpm typecheck が 7 件失敗 | NonNullable<Parameters<...>[0]> で null を剥がし、permission を Electron の union 型 (RequestPermission / CheckPermission) に絞った |
| P2 | fs.ts bounded read が「stat 後 1 byte 追記」で MAX 未満でも誤検知(file watcher 経路の正常 race を拒否) | bounded read を MAX+1 まで段階拡張する形に書き換え、実際に limit を超えた場合だけ reject |

## 詳細

### P1: 型エラーの解消

permission-handler.test.ts で使っていた `Parameters<...>[0]` は Electron 型上
`Handler | null` を返す(setter に null を渡せば handler を unset できる契約)。
これを `NonNullable<...>` で剥がし、permission の `string` 型もそれぞれ
`RequestPermission` / `CheckPermission` に絞り直した:

- handler 型: `NonNullable<Parameters<Session["setPermission*Handler"]>[0]>`
- permission 型: `Parameters<RequestHandler>[1]` / `Parameters<CheckHandler>[1]`

ヘルパー関数 (callRequest / call) の第 1 引数も union 型に narrow し、
test 入力が Electron のリテラル union に閉じることを type-level で保証。
`requestingUrl` / `mediaType` / `isMainFrame` などの details も型に合わせて埋めた。

### P2: bounded read を段階拡張に

前回実装は cap = min(stat.size+1, MAX+1) で読み、`total > stat.size` を上限超
判定にしていた。この実装だと「stat 申告 1MB + 実 1.5MB(MAX 未満)」のような
file watcher 経路の正常 race を誤検知して FILE_TOO_LARGE で reject していた。

新実装の readFileBoundedFromHandle:
1. stat 申告サイズが limit 超なら早期 reject(typical OOM 回避 + 無駄 allocate なし)
2. 実 read は limit+1 byte の hardCap まで段階拡張する buffer で読み続ける
   - 初期 buffer = stat.size + 1(typical case は overhead 最小)
   - 不足したら 2 倍ずつ拡張(hardCap で頭打ち)
   - 実 read が limit を超えた場合のみ reject

これで:
- stat 申告 == 実 size: 通常通り completes
- stat 申告 < 実 size <= limit (外部書込 race): 拡張しつつ正しく受け入れ
- 実 size > limit: hardCap=limit+1 で打ち切り → reject

### bounded read の test 強化

readFileBoundedFromHandle を __testing 経由で export し、fake FileHandle を注入
してロジック単体を verify する describe を追加:

- stat 正確: 通常通り read
- 空ファイル: "" を返す
- stat under-report + 実 size <= limit: 受け入れ(前回実装が誤検知していたケース)
- stat under-report + 実 size > limit: reject
- stat 申告超: 早期 reject

実 fs を使った既存テスト (sparse file の上限超 / 境界) も維持。

unit test: 全 2142 pass / 2 skipped (regression なし)
@ymnao
fix: fs.test.ts の import 順序違反を修正 (#204 PR)
4c2ef5d
| # | 指摘 | 対応 | 理由 |
|---|------|------|------|
| P1 | electron/main/ipc/fs.test.ts:23 の `{ MAX_READ_FILE_BYTES, __testing }` が Biome assist/source/organizeImports に違反し pnpm lint (biome check .) が失敗 | 修正済み | Biome の sort 規則では underscore prefix (`_`) が大文字より前に並ぶため `{ __testing, MAX_READ_FILE_BYTES }` の順に並び替えた |

`biome lint <file>` (ファイル個別) では organizeImports assistant が走らず見逃して
いた。本コミット以降は `biome check .` 相当の全体検証で再現性を担保する。

検証: biome check . がエラーゼロ / typecheck pass / vitest pass。
@ymnao
fix: renderer URL trust escape の修正 (#204 PR)
4a3476c
| # | 指摘 | 対応 | 理由 |
|---|------|------|------|
| P2 | isTrustedRendererOrigin が prod で「file: スキームのローカル HTML」全部を信頼判定。さらに conflict window に will-navigate / setWindowOpenHandler が欠落しており、外部 local HTML へ遷移して clipboard が読まれる経路があった | 修正済み | 信頼判定を「renderer dir 配下のパスかどうか」まで厳密化 + conflict window にも main window と同じ navigation guard を install |

## 詳細

### isTrustedRendererOrigin の origin-only 判定を撤廃

`electron/main/utils/renderer-url.ts` の `isTrustedRendererOrigin` を削除し、
代わりに `isAllowedRendererUrl(url)` を export する形に書き直した。

- dev: ELECTRON_RENDERER_URL の origin + pathname prefix と一致するか
- prod: file: スキーム + pathname が RENDERER_FILE_DIR(`out/renderer`)配下か

pathname まで含めて判定するのが本契約。origin だけだと file: スキーム全体 /
dev origin 全体に対する trust を与えてしまう(実 PoC で再現されたとおり)。

`isAllowedRendererUrl` の実体は index.ts に元から inline で存在していたものを
utils に切り出した。index.ts 側は import で利用するだけ。

### conflict window に navigation guard を install

`electron/main/utils/window-guards.ts` を新設し、`attachNavigationGuards(webContents)`
で `setWindowOpenHandler`(全 deny + 安全な外部 URL は OS ブラウザに委譲)と
`will-navigate`(renderer dir 外を preventDefault + 外部 URL 経路あり)を一括 install。

- `index.ts`: main window 作成箇所の inline guard を attachNavigationGuards 呼び出しに置換
- `ipc/window.ts`: conflict window 作成箇所にも attachNavigationGuards を install。
  これが欠落していたため、conflict window から file:///tmp/evil.html 等に遷移する
  経路で defaultSession が共有された clipboard 権限が引き継がれていた

### permission handler を pathname ベース判定に

`permission-handler.ts` の installMainSessionPermissionHandlers は、判定を
requestingOrigin(origin level)から `details.requestingUrl`(pathname 含む)を
`isAllowedRendererUrl` に通す形に変更。これで origin-only による迂回が塞がる。

setPermissionCheckHandler の details にも requestingUrl が含まれるので、check
経路でも同じく pathname まで含めた判定が可能。

### テスト

- `renderer-url.test.ts`: isAllowedRendererUrl の dev / prod 両モードで
  「pathname まで厳密判定する」事実を verify。特に prod 側で
  `file:///tmp/evil.html` 等が false になることを回帰として固定(本指摘の本旨)
- `window-guards.test.ts`(新規): setWindowOpenHandler が deny を返し、
  will-navigate が renderer dir 外を preventDefault する事を fake WebContents で verify
- `ipc/window.test.ts`: FakeWindow の webContents に setWindowOpenHandler / on を
  追加し、conflict window 作成時に navigation guard が install されることを verify
- electron mock に shell を追加(attachNavigationGuards 依存)

検証: biome check . クリーン / typecheck (web + node + e2e) pass / vitest 全 2148
pass / 2 skipped (regression なし) / electron-vite build clean
@ymnao
fix: renderer-url の Windows 判定回帰 (#204 PR)
02c6041
| # | 指摘 | 対応 | 理由 |
|---|------|------|------|
| P1 | URL.pathname (`/C:/app/out/renderer/index.html`) と RENDERER_FILE_DIR (`C:\app\out\renderer`) を生の文字列比較していたため Windows で正規 renderer URL も拒否され、貼り付け・navigation guard が壊れる | 修正済み | `decodeURIComponent(parsed.pathname)` を廃止し `fileURLToPath(parsed)` で OS ネイティブパスへ変換、`path.relative` + `path.isAbsolute` で base dir 配下を判定するロジックに変更 |

## 変更点

### renderer-url.ts の判定ロジック差し替え

- 旧: `decodeURIComponent(parsed.pathname)` → string startsWith / 等値比較
- 新: `fileURLToPath(parsed)` で OS ネイティブパス取得 → `path.relative(base, osPath)`
  の結果が `""`(base 自体)か、`..` で始まらず絶対パスでもない(配下)場合に true

副次効果として encoded separator (%2F) や `..` segment は URL parser / fileURLToPath
で正規化されるので、`relative` の結果が `..` 始まり / 絶対パスとなる経路で reject される。

判定本体は `isFileUrlInsideDir(url, baseDir, pathOps)` に分離。`pathOps` は
`fileURLToPath` / `relative` / `isAbsolute` を bundle した interface で、production
は host OS の default ops を使う。test 用に Windows ops を差し替え可能にする目的。

### Windows 回帰の cross-OS テスト

`renderer-url.test.ts` に Windows ケースを追加。`fileURLToPath(url, { windows: true })`
(Node 22+)と `node:path/win32` を渡した `pathOps` で host OS(macOS)上でも
Windows 形式の URL 判定を verify できるようにした。

- accepts: `file:///C:/app/out/renderer/index.html` を base `C:\app\out\renderer` 配下と判定
- rejects: 兄弟 dir / 別 drive (D:) / UNC path / `..` escape

POSIX 側も同じ判定セットを cover し、host OS と相手 OS をまたいだ regression を固定。

検証: biome check . クリーン / typecheck (web + node + e2e) pass / vitest 全 2161
pass / 2 skipped / electron-vite build clean
@ymnao
fix: .. prefix の正当な名前を誤検知する判定を厳密化 (#204 PR)
822069a
| # | 指摘 | 対応 | 理由 |
|---|------|------|------|
| P3 | rel.startsWith("..") は base 配下の正当な `..cache/file.js` 等も拒否する | 修正済み | 判定を `rel === ".." \|\| rel.startsWith(\`..${sep}\`)` に変更し、PathOps に `sep` を追加して cross-OS テストを維持 |

## 変更点

### renderer-url.ts の判定強化

`rel.startsWith("..")` 単独判定は parent 参照ではない正当な名前
(`..cache`, `...config` 等、ファイル名として `..` で始まるが
parent 参照ではないもの)も誤って parent と判定して reject していた。

判定を以下に変更:
- `rel === ".."` → parent dir 自体(拒否)
- `rel.startsWith(\`..${sep}\`)` → 親より上位 / 兄弟へのパス(拒否)

`sep` は platform 別の path separator(POSIX: "/", Windows: "\\\\")。`PathOps`
interface に追加して cross-OS テストでも適切な separator を渡せるようにした。
production code は host OS の `path.sep` を default で使う。

### テスト追加

`renderer-url.test.ts` に POSIX / Windows 両モードで「`..` で始まる正当な名前」を
許可する case を追加:

- POSIX: `file:///app/out/renderer/..cache/x.js` / `file:///app/out/renderer/...config`
- Windows: `file:///C:/app/out/renderer/..cache/x.js` / `file:///C:/app/out/renderer/...config`

検証: biome check . クリーン / typecheck pass / vitest 全 2163 pass / 2 skipped
(renderer-url.test.ts は 24 件 = 前回 22 + POSIX 1 + Windows 1)
@ymnao
ymnao merged commit ac394e9 into main Jun 21, 2026
6 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ymnao
ymnao deleted the fix/electron-security-checklist branch June 21, 2026 17:57
@ymnao ymnao mentioned this pull request Jun 24, 2026
chore: v0.5.0 リリース準備 #224
Merged
2 of 3 tasks
ymnao added a commit that referenced this pull request Jun 24, 2026
@ymnao
chore: v0.5.0 リリース準備 (#224)
6126d37
- `CHANGELOG.md` に v0.5.0 セクションを追加
  - Added: #202 → #221 (バックリンクパネル)
  - Fixed: #220 → #222 (タブ切替 undo 履歴消失)
  - Security: #204 → #210 (Electron Tier 1 補完), #205 → #218 (CI スキャン 3 件),
    #223 (codeql-skip stub), #201 (undici 9 件)
  - Internal: #203 → #223 (ADR-0010 MiniSearch Rejected)
  - Dependencies: #199 + #211-#217 → #219 (Dependabot 8 件集約)
- `package.json` の `version` を `0.4.0` → `0.5.0`
- HANDOFF の規約通り、本 commit では `pnpm <script>` を呼ばない
  (lockfile / node_modules には触れない)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ymnao
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.