Skip to content

fix(routing): apply authored headers without overwriting auth cache policy - #669

Merged
Brooooooklyn merged 10 commits into
voidzero-dev:mainfrom
dvkam:fix/579-static-asset-header-overrides
Nov 4, 2026
Merged

Brooooooklyn merged 10 commits into
voidzero-dev:mainfrom
dvkam:fix/579-static-asset-header-overrides

Conversation

@dvkam

@dvkam dvkam commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #579

Apply routing header rules through Hono's header API so configured values replace existing response headers. Keep authentication in control of private and no-store caching, including sign-in responses reached through rewrites or fallbacks.

Preserve last-match precedence and document that header rules also apply to matching error responses.

Validation:

  • Reproduced the CSS and JavaScript failure in build and preview, then verified the fix.
  • 188 focused routing, auth, compiler and real asset-binding tests pass.
  • Workspace type checks pass, 33 tasks. Scoped formatting and lint pass.
  • Full suite: 15,372 passed and 20 failed. Eighteen failures also reproduce on the base revision. The other two pass in isolation.

@dvkam
dvkam marked this pull request as ready for review November 2, 2026 10:55
@Brooooooklyn
Brooooooklyn self-requested a review November 3, 2026 06:34
Brooooooklyn and others added 2 commits November 3, 2026 14:59
… headers

- Refresh the static-asset mark after a rule sets Cache-Control, so auth
  makes the authored file policy private for credentialed requests
  instead of replacing it with no-store.
- Append Set-Cookie rules so the response's own cookies, including the
  Better Auth session, are kept.
- Only count Better Auth cookies when deciding that a response needs the
  auth cache policy; app cookies keep the route's own policy.
- Skip the outer header pass for fallback answers, so only the
  destination's rules apply, as in @void/edge and platform dispatch.
- Docs: say where auth keeps private caching and what a platform does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

Thanks for the fix and the clear write-up. I reviewed it in depth and pushed a follow-up commit, and merged main.

The core change (rules applied through c.header, header middleware inside auth) stays. The commit fixes five cases where the new order or the new "replace" behaviour went wrong:

case                                                      before this commit          now
────────────────────────────────────────────────────────  ──────────────────────────  ─────────────────────────────────────
auth app + any cookie + '/assets/*' immutable rule        no-store (every reload)     private, max-age=31536000, immutable
'/*': Set-Cookie rule on sign-in                          session cookie dropped      both cookies kept ("as written")
auth app, no rules, route sets its own cookie             route policy → no-store     route policy kept
'/*' -> '/index.html' fallback at /assets/old-chunk.js    HTML gets immutable         HTML keeps its own policy
docs: auth keeps private/no-store                         stated for every target     native/local/other runtimes; platform note

How:

  • headerMiddleware refreshes the static-asset mark after a rule changes Cache-Control, so auth still sees a static file and only makes it private for credentialed requests.
  • Set-Cookie rules append instead of replace.
  • The response-cookie trigger in auth now only counts Better Auth cookies (prefix, __Secure-/__Host-, custom cookie names).
  • A fallback answer skips the outer pass: only the destination's rules apply, as in @void/edge and platform dispatch. The recursive-fallback test is back to 'one'.
  • Each case has a test that fails on the previous commit.

Left as is (noted for follow-ups, not part of #579):

  • A 500 raised inside the auth middleware itself (for example a missing secret or database) no longer gets header rules, because the header middleware now sits inside auth.
  • Node/Bun/Deno serve /assets/* before the Hono app, so header rules do not reach those files. This is older behaviour.
  • On a Void platform, dispatch applies header rules after the Worker, so a public Cache-Control rule can replace auth's policy. The docs now say so.

@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-04T04:39:40.601329Z 9e7bdde 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: 933062d109

ℹ️ 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 packages/void/src/router/compile.ts Resolved
@dvkam

dvkam commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Brooooooklyn! I addressed the two later Codex findings in 8910d96. A cookie-free rewrite to /api/auth/get-session now keeps Cache-Control: no-store, and early auth errors keep their configured CORS headers.

You marked the early auth error case as outside #579, so I can move that part to a separate PR if you prefer it that way.

Brooooooklyn and others added 2 commits November 4, 2026 11:47
…rors

- After c.rewrite(), the destination's header pass may already have
  added a Set-Cookie rule value; the outer pass no longer adds it again.
- Mark the inner header pass only once it has run after next(), so a
  notFound handler that throws past it still gets header rules from the
  outer error pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@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: 2d2ff5117e

ℹ️ 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 packages/void/src/runtime/routing.ts Resolved
Comment thread packages/void/src/runtime/routing.ts Resolved
Brooooooklyn and others added 2 commits November 4, 2026 12:29
…ast Set-Cookie rule

- When auth makes a response private, also drop CDN-Cache-Control,
  Cloudflare-CDN-Cache-Control and Surrogate-Control, including values
  a header rule set, so a CDN cannot cache a signed-in page.
- The last matching rule wins for each header name, Set-Cookie
  included. A rewrite's outer pass skips the cookie only when the
  destination pass already added it last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 9e7bdde3a7

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

Brooooooklyn added a commit that referenced this pull request Nov 4, 2026
…697)

Fixes a flaky unit run seen on #669: every test passed, but Vitest
failed the job on an uncaught `Error: write EPIPE` from `dockerBuild` in
`@cloudflare/vite-plugin` (test: "binds Container Durable Objects in the
dev server…", added in #696).

```
dockerBuild: spawn(docker build … -f -) → child.stdin.write(Dockerfile)

old stub   #!/bin/sh
           exit 0                    → on a busy runner the stub exits before the write
                                       → write EPIPE, no error listener → uncaught → job fails
new stub   if [ "$1" = build ]; then cat >/dev/null; fi
           exit 0                    → the stub waits until stdin closes, so the write always lands
```

Reproduced locally by blocking the parent between `spawn` and `write`
(same order as the CI trace):

| stub | result |
| --- | --- |
| old | `Error: write EPIPE` |
| new | ok |

Only `build` reads stdin, so other Docker calls cannot block on it.
Test-only change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn merged commit 2b99e7e into voidzero-dev:main Nov 4, 2026
23 of 27 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.

routing.headers cannot set Cache-Control on static assets

2 participants