Skip to content

fix(serve): /__current-slide に鍵を要求し、::http:: のビルド時取得で表示中のスライドを読まれないようにする - #33

Merged
tanahiro2010 merged 5 commits into
under18dev:mainfrom
tanahiro2010:fix/current-slide-key
Nov 21, 2026

Conversation

@tanahiro2010

Copy link
Copy Markdown
Collaborator

問題

/__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)。
  • 新しいテスト:
    • 鍵なし・トークンを鍵として渡した場合は 403、正しい鍵なら 200
    • 状態ファイルが 0600 で書かれる
  • 既存の ippon current の E2E テストは、鍵込みでそのまま通ります。

/__current-slide はこの PC から localhost 宛てのリクエストならトークン無しで答えていた。
::http:: のビルド時取得は同じ PC の Node から localhost に届くので、他人が書いた Markdown を
build すると、serve 中の別デッキの表示中スライド(ノート・選択文字列・ファイルパス)が
HTML に焼き込まれていた。

起動ごとの agentKey を x-ippon-key ヘッダで要求する。鍵は本人だけが読める
~/.ippon/serve/<port>.json(0600)に置き、ippon current が付けて取りに行く。
::http:: はヘッダを付けられないので届かない。
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T10:58:35.894938Z 0a04d25 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agent.ts Outdated
Comment on lines +33 to +34
mkdirSync(dir, { recursive: true, mode: 0o700 })
writeFileSync(path, JSON.stringify(entry) + '\n', { mode: 0o600 })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 で作り直す。
@tanahiro2010

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agent.ts Outdated
: '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 } })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 にする。
@tanahiro2010

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 0a04d25299

ℹ️ 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".

@tanahiro2010
tanahiro2010 merged commit f7deee4 into under18dev:main Nov 21, 2026
3 checks passed
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