You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/01 23:28:40 UTC
(superset) branch fix/websocket-last-id-validation created (now dab30626792)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a change to branch fix/websocket-last-id-validation
in repository https://gitbox.apache.org/repos/asf/superset.git
at dab30626792 fix(websocket): validate last_id query param format
This branch includes the following new commits:
new dab30626792 fix(websocket): validate last_id query param format
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: fix(websocket): validate last_id query param format
Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch fix/websocket-last-id-validation
in repository https://gitbox.apache.org/repos/asf/superset.git
commit dab30626792feb9ed1b1e7fbe66e6b9cab62ae13
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jun 1 16:28:26 2026 -0700
fix(websocket): validate last_id query param format
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 <no...@anthropic.com>
---
superset-websocket/spec/index.test.ts | 54 +++++++++++++++++++++++++++++++++++
superset-websocket/src/index.ts | 19 +++++++++---
2 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/superset-websocket/spec/index.test.ts b/superset-websocket/spec/index.test.ts
index ce1c82128bd..8c3eebd699a 100644
--- a/superset-websocket/spec/index.test.ts
+++ b/superset-websocket/spec/index.test.ts
@@ -152,6 +152,43 @@ describe('server', () => {
});
});
+ describe('getLastId', () => {
+ const requestWithUrl = (url: string): http.IncomingMessage => {
+ const request = new http.IncomingMessage(new net.Socket());
+ request.url = url;
+ return request;
+ };
+
+ test('returns null when last_id is absent', () => {
+ expect(server.getLastId(requestWithUrl('http://localhost'))).toBeNull();
+ });
+
+ test('returns a well-formed Redis stream ID', () => {
+ expect(
+ server.getLastId(
+ requestWithUrl('http://localhost?last_id=1607477697866-0'),
+ ),
+ ).toEqual('1607477697866-0');
+ });
+
+ test.each([
+ 'abc-xyz',
+ '1607477697866',
+ '1607477697866-',
+ '-0',
+ '1607477697866-0; DROP TABLE',
+ '1607477697866-0-0',
+ ])('returns null for malformed last_id %p', value => {
+ expect(
+ server.getLastId(
+ requestWithUrl(
+ `http://localhost?last_id=${encodeURIComponent(value)}`,
+ ),
+ ),
+ ).toBeNull();
+ });
+ });
+
describe('redisUrlFromConfig', () => {
test('it builds a valid Redis URL from defaults', () => {
expect(
@@ -393,6 +430,23 @@ describe('server', () => {
expect(wsEventMock).toHaveBeenCalledWith('pong', expect.any(Function));
});
+ test('valid JWT, malformed lastId is ignored', async () => {
+ const validToken = jwt.sign({ channel: channelId }, config.jwtSecret);
+ const request = getRequest(
+ validToken,
+ 'http://localhost?last_id=abc-xyz',
+ );
+
+ server.wsConnection(ws, request);
+
+ expect(trackClientSpy).toHaveBeenCalledWith(
+ channelId,
+ socketInstanceExpected,
+ );
+ // Malformed last_id must not trigger a stream range fetch.
+ expect(fetchRangeFromStreamSpy).not.toHaveBeenCalled();
+ });
+
test('valid JWT, with lastId', async () => {
const validToken = jwt.sign({ channel: channelId }, config.jwtSecret);
const lastId = '1615426152415-0';
diff --git a/superset-websocket/src/index.ts b/superset-websocket/src/index.ts
index 5a1587e88b6..92860e73929 100644
--- a/superset-websocket/src/index.ts
+++ b/superset-websocket/src/index.ts
@@ -300,13 +300,24 @@ const readChannelId = (request: http.IncomingMessage): string => {
return channelId;
};
+// Redis stream IDs have the form '<millisecondsTime>-<sequenceNumber>',
+// e.g. '1607477697866-0'.
+const REDIS_STREAM_ID_REGEX = /^\d{1,15}-\d{1,10}$/;
+
/**
- * Extracts the `last_id` query param value from an HTTP request
+ * Extracts the `last_id` query param value from an HTTP request, returning it
+ * only when it is a well-formed Redis stream ID. Malformed values are ignored
+ * (returns null) rather than being passed through to incrementId / Redis.
*/
-const getLastId = (request: http.IncomingMessage): string | null => {
+export const getLastId = (request: http.IncomingMessage): string | null => {
const url = new URL(String(request.url), 'http://0.0.0.0');
- const queryParams = url.searchParams;
- return queryParams.get('last_id');
+ const lastId = url.searchParams.get('last_id');
+ if (lastId === null) return null;
+ if (!REDIS_STREAM_ID_REGEX.test(lastId)) {
+ logger.warn(`Ignoring malformed last_id query param: ${lastId}`);
+ return null;
+ }
+ return lastId;
};
/**