Skip to content

fix(websocket): validate last_id query param format#40626

Merged
rusackas merged 1 commit into
masterfrom
fix/websocket-last-id-validation
Jun 2, 2026
Merged

fix(websocket): validate last_id query param format#40626
rusackas merged 1 commit into
masterfrom
fix/websocket-last-id-validation

Conversation

@rusackas
Copy link
Copy Markdown
Member

@rusackas rusackas commented Jun 1, 2026

SUMMARY

In superset-websocket, getLastId returned the raw last_id query parameter, which is then passed to incrementId and used as the start of a Redis stream range read during the client reconnection flow. Malformed values like last_id=abc-xyz produced ids such as abc-NaN. Redis handles these gracefully and a client can only read its own channel's stream, so the impact is limited — but no positive validation enforced the expected format.

This adds validation: last_id must match the Redis stream ID format /^\d{1,15}-\d{1,10}$/ (<millisecondsTime>-<sequence>); anything else is ignored (returns null), so malformed input is no longer processed.

TESTING INSTRUCTIONS

cd superset-websocket
npm ci
npm test

New tests:

  • getLastId: returns null when absent, returns well-formed IDs, and returns null for a range of malformed inputs (abc-xyz, missing parts, injection-like suffixes, extra segments).
  • wsConnection: a malformed last_id does not trigger a stream range fetch.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

getLastId returned the raw last_id query param, which was then passed to
incrementId and used as a Redis stream range start. Malformed values such as
last_id=abc-xyz produced ids like abc-NaN. Redis handles these gracefully and a
client can only read its own channel's stream, so impact is limited, but no
positive validation enforced the expected format.

Validate last_id against the Redis stream ID format (/^\d{1,15}-\d{1,10}$/) and
return null for anything that doesn't match, so malformed input is ignored
rather than processed. Export getLastId and add unit tests for valid and
malformed values plus a wsConnection test confirming a malformed last_id does
not trigger a stream range fetch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 1, 2026

Code Review Agent Run #a8a300

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: dab3062..dab3062
    • superset-websocket/spec/index.test.ts
    • superset-websocket/src/index.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 1, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit dab3062
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a1e15ac4f81b200071f4fee
😎 Deploy Preview https://deploy-preview-40626--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds positive validation for the last_id query parameter in the Superset websocket server. Previously, getLastId returned the raw value without validation, allowing malformed inputs to be passed downstream to Redis stream operations. The change enforces the Redis stream ID format <millisecondsTime>-<sequence> via regex and returns null for malformed values.

Changes:

  • Add REDIS_STREAM_ID_REGEX and validate last_id in getLastId, returning null (with a warning log) for malformed values.
  • Export getLastId so it can be unit-tested.
  • Add unit tests for getLastId and a wsConnection test asserting malformed last_id does not trigger a stream range fetch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
superset-websocket/src/index.ts Add regex validation for last_id, export getLastId, log and ignore malformed values.
superset-websocket/spec/index.test.ts Add tests for getLastId and for ignoring malformed last_id in wsConnection.

@sha174n sha174n added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Jun 2, 2026
@rusackas rusackas merged commit 19c2b67 into master Jun 2, 2026
61 checks passed
@rusackas rusackas deleted the fix/websocket-last-id-validation branch June 2, 2026 18:36
@github-project-automation github-project-automation Bot moved this from Needs Review to Approved and/or Merged in Superset Review Help Wanted Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-if-green If approved and tests are green, please go ahead and merge it for me size/M

Projects

Status: Approved and/or Merged

Development

Successfully merging this pull request may close these issues.

4 participants