Public: anyone can read this; the crew can change it.

One rule decides `Secure` on every cookie the forge sets: the visitor cookie on an app host is Secure over https #6117

opened this

Merged 40d 21h ago, live in production

The visitor, flash and session cookies now get Secure from one rule, so GET /forge/notes on the https app host now sets it. I ran type-check and the new test plus cookie-flags and apps-feedback; they pass. I did not run the full suite or design-lint; the forge's check runs the full suite on push.

Notes

opened this

The visitor, flash and session cookies now get Secure from one rule, so GET /__forge/notes on the https app host now sets it. I ran type-check and the new test plus cookie-flags and apps-feedback; they pass. I did not run the full suite or design-lint; the forge's check runs the full suite on push.

  • The rule: secureFor(url, forgeUrl?, appUrl?) in src/http/cookie_secure.ts is true when the request, the forge's address or the app's address is https.
  • Visitor cookie: src/apps/proxy.ts uses it for the visitor cookie and for the app grant and sign-out cookies. It still honours x-forwarded-proto. Proxy callers pass no appUrl; the forge address covers app hosts.
  • Session cookie: sessionCookie in site.ts uses it.
  • Flash cookies: flashCookie and clearFlashCookie take the forge's address, and redirect takes a new forgeUrl option. I passed ctx.app.config.url at the places that redirect with a flash. A flash redirect that doesn't pass forgeUrl falls back to the request scheme alone, as before.
  • Test: test/cookie-secure.test.ts has the unit cases, an http request to an https:// forge, and a plain-http forge. With the src changes stashed, the flash/session case and the visitor case (http request to an https:// forge) fail. The unit test of secureFor itself passes there, since the new file stays in place.

I left forge_theme and forge_mode on their own url.protocol check, because the issue names only the visitor, flash and session cookies. They would change the same way if you want them on the rule too.

Closes #6095

3 earlier comments
commented

The visitor, flash and session cookies now get Secure from one rule, so GET /__forge/notes on the https app host now sets it. I ran type-check and the new test plus cookie-flags and apps-feedback; they pass. I did not run the full suite or design-lint; the forge's check runs the full suite on push.

  • The rule: secureFor(url, forgeUrl?, appUrl?) in src/http/cookie_secure.ts is true when the request, the forge's address or the app's address is https.
  • Visitor cookie: src/apps/proxy.ts uses it for the visitor cookie and for the app grant and sign-out cookies. It still honours x-forwarded-proto. Proxy callers pass no appUrl; the forge address covers app hosts.
  • Session cookie: sessionCookie in site.ts uses it.
  • Flash cookies: flashCookie and clearFlashCookie take the forge's address, and redirect takes a new forgeUrl option. I passed ctx.app.config.url at the places that redirect with a flash. A flash redirect that doesn't pass forgeUrl falls back to the request scheme alone, as before.
  • Test: test/cookie-secure.test.ts has the unit cases, an http request to an https:// forge, and a plain-http forge. With the src changes stashed, the flash/session case and the visitor case (http request to an https:// forge) fail. The unit test of secureFor itself passes there, since the new file stays in place.

I left forge_theme and forge_mode on their own url.protocol check, because the issue names only the visitor, flash and session cookies. They would change the same way if you want them on the rule too.

commented

I merged main into this branch and pushed. The one conflict was in src/apps/proxy.ts, in the grant-cookie clearing redirect.

  • Resolution: I kept this pull's single Secure rule (proxySecure(request, url, runtime.options.forgeUrl)). I also kept main's change that wraps that redirect in securityFloor(...), so the response gets the security headers and the cookie flag comes from the one shared rule. main's separate x-forwarded-proto check for Secure is gone.
  • Tests: The three cookie and proxy suites pass (10 tests, test/apps-proxy-credentials.test.ts, test/cookie-flags.test.ts, test/cookie-secure.test.ts), and bun x tsc --noEmit reports no errors.
  • Not run: The full bun test ran over 10 minutes here without finishing, so I stopped it. The forge's check on this push will run the whole suite.
commented

Every cookie the forge sets now decides Secure through secureFor. The two suites I ran, test/cookie-secure.test.ts and test/cookie-flags.test.ts, pass and the type check is clean. I did not run the full bun test; the forge's check will.

  • Parent sign-in state cookie: cookieHeader in src/http/rp.ts now uses secureFor(url, forgeUrl), and I exported it so the test can call it directly.
  • Theme cookie: themeSubmit uses secureFor(ctx.url, ctx.app.config.url).
  • Mode cookie: withoutMode in src/http/server.ts now takes the forge's address and uses secureFor.
  • Tests: test/cookie-secure.test.ts has one new assertion for each of the three. Each uses an http request against an https forge and expects ; Secure. The forge_theme and forge_mode assertions go through a served forge configured with an https url. The cookieHeader one calls the function directly, so it checks the rule but not the call site; the sign-in state cookie also has the rp.ts walk in cookie-flags.
  • Import: the secureFor import in src/apps/proxy.ts now sits with the other imports, below the module's doc comment.

I left two of the smaller points alone.

  • redirect flash parameter: I did not change redirect in src/web/layout.ts to take a precomputed secure. You marked it optional, and every current caller already passes the forge's address.
  • Shared runtime.options: the visitor-cookie tests still mutate runtime.options in sequence. They pass, and the new tests do not touch it.
commented

I removed the unused appUrl parameter from secureFor. The rule is now: the request is https, or the forge's own address is https. test/cookie-secure.test.ts passes (7 tests) and the type check is clean. I did not run the full suite.

  • Dead branch: secureFor in src/http/cookie_secure.ts no longer takes appUrl, and the doc comment drops the clause about the app's public address. No caller ever passed it.
  • Test: I deleted the third expect in the secureFor unit test, the one that used appUrl.
  • App hosts: the proxy still decides from the forge address and the request, as before. I did not give app hosts their own scheme, since you offered removal as the alternative.
  • Optional flashTo point: I left redirect's forgeUrl option as it is. Every current caller passes it.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs