Repository navigation
fix(serve): /__current-slide に鍵を要求し、::http:: のビルド時取得で表示中のスライドを読まれないようにする - #33
Conversation
/__current-slide はこの PC から localhost 宛てのリクエストならトークン無しで答えていた。 ::http:: のビルド時取得は同じ PC の Node から localhost に届くので、他人が書いた Markdown を build すると、serve 中の別デッキの表示中スライド(ノート・選択文字列・ファイルパス)が HTML に焼き込まれていた。 起動ごとの agentKey を x-ippon-key ヘッダで要求する。鍵は本人だけが読める ~/.ippon/serve/<port>.json(0600)に置き、ippon current が付けて取りに行く。 ::http:: はヘッダを付けられないので届かない。
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af3c14be11
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| mkdirSync(dir, { recursive: true, mode: 0o700 }) | ||
| writeFileSync(path, JSON.stringify(entry) + '\n', { mode: 0o600 }) |
There was a problem hiding this comment.
Enforce private permissions on existing state files
If a previous-version server leaves a 0644 state file after an unclean exit and its port is reused after upgrading, these mode options do not secure the existing file or directory; they only affect newly created paths. With the old 0755 state directory and a traversable home directory, the newly persisted agentKey is therefore readable by other local users, who can use it to retrieve slide Markdown, notes, and selection over loopback. Enforce private permissions before writing credentials to existing paths, or safely replace the entry with a private file, and cover this upgrade case in the permissions test.
Useful? React with 👍 / 👎.
writeFileSync / mkdirSync の mode は新しく作るときにしか効かない。異常終了した旧版の 0644 のファイルが残ったままポートが再利用されると、他のユーザーから鍵を読めた。 ディレクトリは 0700 に絞り直し、ファイルは消してから wx・0600 で作り直す。
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa0531b8f4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| : 'ippon serve が見つかりません(先に ippon serve slide.md を起動してください)' | ||
| ) | ||
| const res = await fetch(`http://localhost:${e.port}/__current-slide`) | ||
| const res = await fetch(`http://localhost:${e.port}/__current-slide`, { headers: { 'x-ippon-key': e.key } }) |
There was a problem hiding this comment.
Send the agent key to the server's IPv4 loopback address
On dual-stack hosts where localhost resolves to ::1 first (reproduced on Linux with Node 24), the default serve() listener is IPv4-only (src/serve.ts:312). Another local user can bind ::1 on the same port and receive the newly added x-ippon-key when the owner runs ippon current; that captured key then authorizes retrieval of the private Markdown, notes, and selection from the real IPv4 server. The private state-file permissions therefore do not prevent this credential theft. Send the credential to 127.0.0.1, or persist and use an address actually bound by the server, rather than resolving localhost.
Useful? React with 👍 / 👎.
serve は IPv4(0.0.0.0)で待ち受けるが、localhost が ::1 に先に解決される環境では、 他のユーザーが同じポートの ::1 で待ち受けていると x-ippon-key をそちらに送ってしまう。 ippon current と起動時に表示する currentUrl を 127.0.0.1 にする。
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
問題
/__current-slideは「この PC からlocalhost宛て」のリクエストなら、トークン無しで答えていました。::http::のビルド時取得は同じ PC の Node からlocalhostに届くので、他人が書いた次のような Markdown をippon buildすると問題が起きます。::http method=GET url=http://localhost:3000/__current-slide::そのとき
ippon serveしている別のデッキの表示中スライドが、build した HTML に焼き込まれます。焼き込まれるのは Markdown(::note::を含む)、選択中の文字列、ファイルの絶対パスです。ポートが分からなくても、候補を並べれば並列に取得されます。ブラウザ(他サイト・デッキの「再送信」)からは、CORS ヘッダが無いので読めません。経路は Node の build 時取得だけです。
修正
ippon serveが起動ごとにagentKeyを作ります。/__current-slideはx-ippon-keyヘッダにその鍵が無ければ 403 を返します。localhost / Host の確認はそのまま残します。~/.ippon/serve/<port>.jsonに置きます。このファイルは 0600 で書き、本人だけが読めます。ippon currentはここから鍵を読んで付けます。::http::はヘッダを付けられない(HttpSpecは method と url だけ)ので届きません。curl例も、ヘッダ付きに変えました。互換性
curl http://localhost:<port>/__current-slideを直接叩いている場合は 403 になります。ippon currentを使うか、起動時に表示されるヘッダ付きのcurlに置き換えてください。docs(日英)、README、CLAUDE.md を更新しています。確認
npm run typecheckとnpm testが通ります(82 件 pass)。ippon currentの E2E テストは、鍵込みでそのまま通ります。