Skip to content

[haxcms-nodejs] Login returns siteToken with the JWT - #79

Merged
btopro merged 3 commits into
mainfrom
security/require-session-tokens-default
Oct 19, 2026
Merged

btopro merged 3 commits into
mainfrom
security/require-session-tokens-default

Conversation

@btopro

@btopro btopro commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #71 and haxtheweb/webcomponents#882. Parity PR: haxtheweb/haxcms-php#662.

Scope after today's main updates

The default flip of security.requireSessionForRequestTokens (on by default) has already landed on main, in your own commit 01b1762, together with the haxtheweb/webcomponents#882 build (2e2eda5). I merged main in and took its versions of HAXCMS.js and the flag tests. This PR is now just the login part:

  • Login returns siteToken too. It now uses getSessionRequestTokens(req), the same helper refresh and connection-test use. userToken is always returned; siteToken is returned when a site context resolves (body, path, Referer, single-site). With anonymous connection-settings no longer handing out tokens, this lets an in-page login on a site page save straight away instead of waiting for the first refresh.
  • loginRoute is now async. session.js already awaits it.
File Change
src/systemRoutes/v1/routes/login.js async; returns Object.assign({status, jwt}, getSessionRequestTokens(req)), with a userToken fallback if that throws
test/unit/session-hardening.test.cjs realLogin and the login test await the async route; new tests: login from a site page returns that site's siteToken, and a failed login carries no tokens

Tests

  • npm test locally: 2689 pass, 0 fail. npm run test:coverage also passes locally.
  • CI on the current head: e2e ✅ and unit + API conformance ✅. The first unit-job run failed in its Coverage step; it passed on re-run with no code change.
  • The e2e job now runs against the refreshed build with the flag on by default, so it also confirms the full login → create → edit → save flow works with tokens coming from login/refresh/connection-test.

https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF


Generated by Claude Code

…lt; login returns siteToken

Follow-up to #71. The webcomponents front-end now stores the request tokens
that login, refresh and connection-test return (haxtheweb/webcomponents PR,
jwt-login session-tokens event), so anonymous connection-settings loads no
longer need them.

- security.requireSessionForRequestTokens now defaults to TRUE. A boolean in
  config.json is used as-is (false opts out); strings go through the
  1/true/yes list; anything else falls back to the default. The env var
  HAXCMS_REQUIRE_SESSION_FOR_REQUEST_TOKENS still overrides both ways.
- login now returns the same request tokens as refresh/connection-test:
  userToken always, siteToken when a site context resolves (body, path,
  Referer, single-site). An in-page login on a site page can save without
  waiting for the first refresh.
- loginRoute is async (getSessionRequestTokens resolves the single-site
  context); session.js already awaits it.
- tests: default on, boolean/string/other config resolution, opt-out keeps
  the old anonymous behaviour, login from a site page returns siteToken,
  failed login carries no tokens.

Do not merge until src/public/build carries the new front-end: with the old
build, anonymous editor loads have no tokens and in-page login loops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF
Copilot AI balanced review requested due to automatic review settings October 19, 2026 17:28
@codesandbox

codesandbox Bot commented Oct 19, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Resolve the HAXCMS.js conflict with main's Prettier reformat by taking main's
file and re-applying getRequireSessionForRequestTokens (default true, booleans
used as-is) in the new style.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF
main's security update already flips requireSessionForRequestTokens to
default on (same semantics as haxcms-php L-3), so take main's HAXCMS.js and
session tests. What this PR still adds: login returns siteToken too
(getSessionRequestTokens, async route), the test helper awaits the async
route, and tests for login from a site page and a failed login.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF
@btopro btopro changed the title [haxcms-nodejs] Require a session for request tokens by default; login returns siteToken [haxcms-nodejs] Login returns siteToken with the JWT Oct 19, 2026
@btopro
btopro marked this pull request as ready for review October 19, 2026 20:31
@btopro
btopro merged commit dadf398 into main Oct 19, 2026
7 of 8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 2026
@btopro
btopro deleted the security/require-session-tokens-default branch October 19, 2026 21:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants