Repository navigation
fix: harden KDS WebSocket admission, printer targets, and desktop runtime boundaries - #1511
Conversation
…g redaction, child popups, and image ETag checks
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing |
PR Summary by QodoHarden KDS admission, printer dispatch, and desktop boundaries
AI Description
Diagram
High-Level Assessment
Files changed (23)
|
Code Review by Qodo
1.
|
…n/printers/thermal.ts` (and audited all sibling string-parsing sites introduced in this PR): 1. **Invariant**: All string normalization and redaction on untrusted/user-provided inputs must execute in linear time $O(n)$ without polynomial regex backtracking. 2. **Fixes**: - [`validateNetworkPrinterTarget`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M6WSBE3T8M3N1EPPT13YJSBN/main/printers/thermal.ts#L5039-L5058): Replaced `.replace(/\.+$/, '')` with a backward index scan trimming trailing dots in $O(n)$ time and rejecting dot-only hostnames. - [`expandPrinterIpv6Groups`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M6WSBE3T8M3N1EPPT13YJSBN/main/printers/thermal.ts#L4982-L4993): Replaced `/^(.*:)(\d{1,3}(?:\.\d{1,3}){3})$/` with `lastIndexOf(':')` and explicit octet splitting to avoid greedy prefix backtracking. - [`sanitizeLogTail`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M6WSBE3T8M3N1EPPT13YJSBN/main/lib/log-sanitizer.ts#L1-L21): Anchored `AUTH_HEADER_RE` and `QUOTED_KEY_VALUE_RE` with word boundaries and removed overlapping `\s*["']?\s*` quantifiers. - [`tests/printer-api.test.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M6WSBE3T8M3N1EPPT13YJSBN/tests/printer-api.test.ts#L862-L877): Added regression cases for trailing-dot FQDNs (`metadata.google.internal.`, `localhost.`) and dot-only hostnames (`...`). 3. **Verification**: `npm run lint`, `npm run build`, `npx tsx tests/printer-api.test.ts`, `npx tsx tests/support-ticket.test.ts`, `npx tsx tests/update-ipc-sender-validation.test.ts`, and `git diff --check` all passed
…d port checks, and harden spool open
Intent
Proceed with sequential local implementation Batch 3 (Items 7, 8, and 9 of the revised security plan), subject to these decisions and acceptance criteria:
3001-3003across the network.npm run lint,npm run build, andnpm test; run browser/Electron checks for affected flows and documentation checks for changed contracts. Report fresh results, limitations, final diff, and git status.What Changed
:3001) and standalone KDS (:3002) listeners with Origin validation, a 5-connection-per-IP pending-authentication cap alongside the 25-connection global pending limit, and immediate pruning of closing sockets.wx,0o600) with tracked cleanup.get-log-tailIPC and/api/support-ticketlog uploads, attachdid-create-windownavigation and nested-popup guards to Electron child windows while permitting localblob:print previews, and evaluateIf-None-MatchETags onGET /api/products/:id/imagebefore decoding image payloads.Risk Assessment
✅ Low: The security hardening changes across KDS WebSocket admission, network printer target validation, exclusive spool file handling, diagnostic log redaction, child popup navigation guards, and product image ETag/size bounds are well-bounded, linear-time, and thoroughly covered by regression tests.
Testing
Ran 11 targeted regression suites covering KDS WebSocket admission/revalidation, network printer target validation, Windows/CUPS spool file exclusivity, support ticket and IPC log tail redaction, child-popup navigation guards, URL allowlist, CORS, and product image ETag/bounds handling, and stood up the live Express (:3001) and KDS (:3002) servers in an isolated environment to drive all 8 happy-path and adversarial scenarios end-to-end with evidence captured in live-batch3-verification.json (no visual UI layout changes were introduced in this backend/IPC security batch).
node tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.tsnode tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.tsnpm run test:printer-apinpm run test:printer-apinpx ts-node --transpile-only -P tests/tsconfig.json tests/windows-print-error-detail.test.tsnpm run test:support-ticketnpm run test:update-ipc-sender-validation, andnpm run test:url-allowlistnpm run test:product-imagesEvidence: Live Batch 3 verification output against running POS and KDS servers
{ "kdsFairnessAndOrigin": { "apiPort": 3001, "kdsPort": 3002, "evilOriginMainStatus": 403, "evilOriginKdsStatus": 403, "clientCountAfterEvilOrigin": 0, "pendingCountWave1": 5, "sixthUnauthenticatedMainStatus": 429, "sixthUnauthenticatedKdsStatus": 429, "countAfterSixthRejected": 5, "totalAuthenticatedCoexisting": 10 }, "printerHardeningAndCompatibility": { "createValidPrinterStatus": 201, "dispatchValidOk": true, "receivedByMockPrinter": "HELLO ESC/POS", "blockedResults": [ { "label": "cloud metadata IPv4", "apiStatus": 400, "dispatchOk": false }, { "label": "cloud metadata FQDN", "apiStatus": 400, "dispatchOk": false }, { "label": "unspecified IPv4", "apiStatus": 400, "dispatchOk": false }, { "label": "own API port", "apiStatus": 400, "dispatchOk": false }, { "label": "own KDS port", "apiStatus": 400, "dispatchOk": false } ] }, "credentialRedaction": { "supportTicketStatus": 202, "containsAnyRawSecret": false, "ipcText": "[2026-11-08 12:20:00.123] [error] [Auth] Handshake failed code=ECONNRESET\nAuthorization: Bearer [REDACTED]\n{"x-master-pin":"[REDACTED]","password":"[REDACTED]","pin":"[REDACTED]"}\nx-api-key=[REDACTED] api_key="[REDACTED]" apiKey=[REDACTED]\noauth access_token="[REDACTED]" refresh_token=[REDACTED]\n at verifySocket (/app/main/services/kds.ts:140:11)" }, "childWindowGuards": { "nestedWindowOpenAction": "deny", "navResults": [ { "url": "about:blank", "prevented": false, "openedExternally": null }, { "url": "blob:http://localhost:3001/menu-print-uuid", "prevented": false, "openedExternally": null }, { "url": "http://localhost:3001/kds", "prevented": false, "openedExternally": null }, { "url": "https://example.com/external-help", "prevented": true, "openedExternally": "https://example.com/external-help" }, { "url": "blob:https://evil.example/payload", "prevented": true, "openedExternally": null }, { "url": "javascript:alert(1)", "prevented": true, "openedExternally": null } ] }, "productImageEtagAndBounds": { "initialGetStatus": 200, "notModifiedStatus": 304, "decodeCountOn304": 0, "oversizedGetStatus": 404, "decodeCountOnOversized": 0 } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
node tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.tsnode tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.tsnpm run test:printer-apinpm run test:printer-apinpx ts-node --transpile-only -P tests/tsconfig.json tests/windows-print-error-detail.test.tsnpm run test:support-ticketnpm run test:update-ipc-sender-validation, andnpm run test:url-allowlistnpm run test:product-imagesnode tests/run-electron-node-test.cjs tests/kds-websocket-revalidation.test.tsnpm run test:printer-apinpm run test:product-imagesnpm run test:support-ticketnpm run test:update-ipc-sender-validationnpx ts-node --transpile-only -P tests/tsconfig.json tests/windows-print-error-detail.test.tsnpm run test:url-allowlistnpm run test:corsnpm run test:titlebar-window-optionsnpm run test:kds-window-hardeningnpm run test:script-coveragenode tests/run-electron-node-test.cjs /tmp/live-verify-batch3.ts✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.