Skip to content

feat: mark session cookies Secure behind an https public URL - #110

Merged
TusanHomichi merged 9 commits into
mainfrom
claude/93-secure-cookie
Oct 15, 2026
Merged

TusanHomichi merged 9 commits into
mainfrom
claude/93-secure-cookie

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Primary Issue

Closes #93

Problem And Outcome

ADR 0004 deferred the Secure cookie attribute to deployment hardening. Without it, a browser sends the session cookie over plain HTTP whenever the installation is reached that way. The service speaks plain HTTP behind a TLS reverse proxy, so it can't tell on its own whether the browser used HTTPS, and forwarded headers can be forged.

After this PR, an operator states the address people use: --public-url, CONSOLEBOOK_PUBLIC_URL, or the installer's --public-url. An https:// address does two things:

  • marks every session cookie Secure. That decision comes only from this setting, never from request headers;
  • revokes, at start, any live session that wasn't issued Secure, so an old cookie stops being a credential at once.

A wrong or missing address degrades visibly, never silently.

Changes

  • public_url.rs: the typed PublicUrl origin.
    • Accepts http(s)://, a host, and an optional port.
    • Validates the host: a DNS name of alphanumeric-or-hyphen labels, a plain dotted IPv4 address (a numeric last label must be canonical IPv4), or a bracketed IPv6 address that parses.
    • Validates the port: 1 to 65535.
    • Stores the origin as a browser writes it: lowercase host, compressed IPv6, no default port.
    • Refuses a path, query, fragment, or user info at startup.
  • Cookies:
    • session_cookie and removal_cookie take secure;
    • sessions::create takes a typed CookieTransport;
    • migration 0016 adds a session_secure_cookie table, a new owner, so session itself is unchanged as the schema guard requires;
    • sessions::revoke_not_secure runs at start in Secure mode.
  • serve:
    • logs the cookie choice;
    • warns when listening beyond loopback without an https:// URL;
    • points the first-run setup instruction at the public URL.
  • /api/instance reports public_url. The sign-in page names the right address when the browser's origin differs.
  • Installer:
    • --public-url is validated by the unpacked release's own parser (hidden check-public-url) before anything is stopped or written;
    • the normalized origin is stored, and it's carried into the --no-service start command.
  • Docs:
    • docs/install.md "HTTPS (required before real records)", with a tested Caddy recipe, and a note that enabling it signs everyone out once;
    • ADR 0025;
    • ADR 0004 and ADR 0023 amended;
    • development index and CHANGELOG.

Correction rung: 1. One typed setting decides Secure; one parser serves both the server and the installer.

Verification

  • tests/public_url.rs:
    • Secure, HttpOnly, and SameSite=Strict on login and logout cookies with an https URL, and none without one or with an http one;
    • /api/instance reports the URL;
    • a plain session is revoked while a Secure one survives, and a second call revokes nothing;
    • sign-in behind https records the session as Secure;
    • the built binary's check-public-url agrees with the parser.
  • Parser unit tests cover accepted forms, canonical origins, and the refused forms Codex raised: empty host, bad ports, broken IPv6, non-canonical IPv4.
  • Negative controls fail with each fix removed: the authority check, the numeric-host check, and revocation.
  • web/e2e/public-url.spec.ts (2 tests): the sign-in notice shows when the origin differs, and doesn't when it matches.
  • Release workflow, on a real systemd install:
    • the env file and /api/instance carry the URL;
    • the journal shows "session cookies are marked Secure" and "open https://…/ in a web browser";
    • a malformed --public-url is refused with the service still active and the setting unchanged;
    • the --no-service command carries the URL.
  • Full local proof on 595a489 (scripts/proof.py, euid 0 with DAC capabilities dropped): passed, all 7 gates. Browser suite 61 expected, 0 unexpected, 0 flaky. Receipt .proof/20261014T234746Z-595a489e89a2/receipt.json, sha256 53fb5594f5d1ac319b935b312b8a06e6e01e7e9d6652514736284e63a125edfd.
  • Codex: eight findings. Seven were fixed as above. One was declined with reasoning on its thread: canonicalizing IPv4-mapped IPv6 public URLs, which only affects a cosmetic notice for a configuration nobody makes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

ADR 0004 deferred the Secure cookie attribute to deployment hardening.
An operator now states the address people use (serve --public-url /
CONSOLEBOOK_PUBLIC_URL; installer --public-url). It parses into a typed
origin; an https:// one marks the sign-in and sign-out cookies Secure.
The decision never comes from forwarded headers a direct client could
forge.

A misconfiguration is visible instead of silent: serve warns when it
listens beyond loopback without an https public URL, /api/instance
reports the public URL, and the sign-in page names it to a browser that
arrived by another address (a dropped Secure cookie would otherwise
make sign-in bounce without explanation).

ADR 0025 records the decision and amends ADR 0004. The install guide
gives a Caddy configuration, run in front of this build: setup and
sign-in through it returned a Secure cookie that kept the session.

Tests: parsing; Secure set with an https URL and absent otherwise, on
both sign-in and sign-out (forcing it off fails the test); the instance
field; a browser test for the sign-in note; a release-workflow step for
the installer option.

Closes #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
# Conflicts:
#	CHANGELOG.md
#	docs/decisions/0023-linux-installation-lifecycle.md
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T23:49:39.771151Z 595a489 New commits
ℹ️ 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: db7758c73b

ℹ️ 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 install/install.sh Resolved
…tarts

PublicUrl now refuses an empty host, a non-numeric or out-of-range port,
an unclosed or invalid IPv6 literal, and malformed host names, so serve
never advertises an address no browser can open. The installer's
--no-service start command carries CONSOLEBOOK_PUBLIC_URL, which the
release workflow now checks.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: 3f7f98c9a3

ℹ️ 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 crates/consolebook-server/src/main.rs Resolved
…al IPv4 hosts

The first-run log now sends operators to the public URL when one is set,
not http://<bind>/, where setup would end at a sign-in whose Secure cookie
never sticks. A host whose last label is numeric must be a plain dotted
IPv4 address, since browsers refuse 999.999.999.999 and rewrite 0x7f.0.0.1.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: 5c8b33cabf

ℹ️ 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 install/install.sh Resolved
… changing anything

A hidden check-public-url command parses the address exactly as serve does
and prints its origin. The installer runs it from the unpacked release
before stopping the service or writing settings, so a malformed address
fails the install with nothing changed instead of leaving the service down.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: 2330800776

ℹ️ 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 web/src/routes/login/+page.svelte Resolved
Lowercase host, compressed IPv6, and no default port, so the sign-in page's
comparison with location.origin does not warn a browser that is already at
the configured address.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

@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: c13a4ad282

ℹ️ 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 crates/consolebook-server/src/http.rs Resolved
…tarts

Each session now records whether its cookie was issued Secure (migration
0016). serve, started with an https:// public URL, revokes every live
session that was not, so a cookie a browser may still send over plain HTTP
stops being a credential at once instead of lasting up to its 12-hour
expiry.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

Copy link
Copy Markdown
Member Author

@codex review


Generated by Claude Code

The schema-preservation guard (enrollment_event_schema) requires later
migrations to add owners, never change existing objects, so migration 0016
creates session_secure_cookie instead of altering session. Session creation
writes both rows in one immediate write transaction.

Refs #93

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts

@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: 595a489e89

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

@TusanHomichi
TusanHomichi merged commit 60a4267 into main Oct 15, 2026
4 checks passed
@TusanHomichi
TusanHomichi deleted the claude/93-secure-cookie branch October 15, 2026 00:00
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.

deploy: supported HTTPS front end and the Secure session cookie

2 participants