Skip to content

Fix crash on comms auth packet when adminAuth is not set - #5988

Merged
knolleary merged 1 commit into
node-red:mainfrom
sankalpsthakur:fix/5986-comms-auth-without-adminauth
Oct 13, 2026
Merged

knolleary merged 1 commit into
node-red:mainfrom
sankalpsthakur:fix/5986-comms-auth-without-adminauth

Conversation

@sankalpsthakur

Copy link
Copy Markdown
Contributor
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Fixes #5986

Without adminAuth, any {"auth": ...} packet sent to /comms stops Node-RED. Tokens.init only runs when adminAuth is set, but comms.js still passed the packet to handleAuthPacket, and Tokens.get then dereferenced the undefined storage. The TypeError is thrown inside the websocket message handler, so the runtime exits. An editor tab left open while adminAuth is removed sends its old token on every reconnect.

Change in editor-api/lib/editor/comms.js: when adminAuth is not set, an auth packet is acknowledged with {"auth":"ok"} and not checked. The connection is already active, so this only lets the editor finish connecting. Replying fail would send the editor to a login dialog with no prompts, and no reply would leave it never re-subscribing. With adminAuth set, auth packets are handled as before.

New test in test/unit/@node-red/editor-api/lib/editor/comms_spec.js (default settings, no adminAuth): {"auth":"x"} gets {"auth":"ok"}, then subscribe/publish still work.

Before the fix (main 935b8d3, the new test run alone with -g), it fails with Uncaught TypeError: Cannot read properties of undefined (reading 'getSessions').

After the fix (Node 22.23.2):

npx mocha --exit test/unit/@node-red/editor-api/lib/editor/comms_spec.js
  19 passing
npx mocha --exit "test/unit/@node-red/editor-api/**/*_spec.js"
  237 passing, 1 pending, 3 failing

The same 3 tests fail on main without this change (236 passing): serves icons, returns the default icon for invalid paths and serves the editor resources. They need the built editor assets.

I also ran Node-RED from this branch with the default settings file and sent the command from the issue. Before the fix it exited with the TypeError above. After the fix the client gets {"auth":"ok"} and Node-RED keeps running.

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

I ran the editor-api unit tests above rather than the full npm run test, which builds the editor first.

AI/LLM disclosure

  • AI coding tools (Claude Code) were used to write this change, the tests and this description.
  • The change was reviewed and the tests above were run locally before submitting.

The tokens store is only initialised when adminAuth is set, but an auth
packet on the comms websocket was still checked against it. The
TypeError thrown inside the websocket message handler exited the
runtime. An editor left open while adminAuth was removed sends its old
token on every reconnect, so the restarted runtime kept crashing.

Without adminAuth the connection is already authorised, so the packet
is now acknowledged with auth:ok and the editor completes its
connection.

Fixes node-red#5986
@knolleary
knolleary merged commit 442a311 into node-red:main Oct 13, 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.

Crash via websocket message with old session

2 participants