From a1d73f4809aead0bba1311734ae5ee6cb219f64f Mon Sep 17 00:00:00 2001 From: prsmith777 Date: Mon, 2 Nov 2026 12:12:38 -0700 Subject: [PATCH] Fix out-of-range Home Assistant image IDs and prepare Community 0.1.61 --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- CHANGELOG.md | 6 ++++++ docs/HOME_ASSISTANT.md | 6 ++++++ docs/INSTALL.md | 2 +- docs/UPDATES.md | 12 ++++++++--- lib/help-manual.mjs | 4 ++-- lib/home-assistant-display.mjs | 4 +++- lib/release-info.mjs | 11 ++++------ package.json | 2 +- scripts/test-community-browser.mjs | 5 +++++ scripts/test-community-bugfixes-postgres.mjs | 5 +++++ test/help-manual.test.mjs | 2 +- test/home-assistant-display.test.mjs | 21 ++++++++++++++++++++ test/release-info.test.mjs | 21 ++++++++++---------- 14 files changed, 75 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index bf29113..2bf3ea9 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -16,7 +16,7 @@ body: attributes: label: ALPR Community version description: Find this under Settings → Release. Include the source revision there when reporting an installation or update problem. - placeholder: v0.1.60 + placeholder: v0.1.61 validations: required: true diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7cd92..eed633c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.1.61 — 2026-11-02 + +- Return HTTP 404 for Home Assistant display image IDs outside the supported PostgreSQL integer range. Reject these IDs before querying images, avoiding the previous HTTP 503 response. +- Preserve display authentication, camera scope, expiration, revocation and read-only restrictions. Add integer-boundary unit, PostgreSQL and production-browser regression checks. +- Update User Guide 3.29 and current release/install/update guidance. This patch adds no database migrations; existing installations use the normal updater. + ## 0.1.60 — 2026-11-02 - Track ordered SQL migrations with verified checksums and legacy completion markers. Preserve the single-file updater entry point, atomic application, count validation and rollback. Completed cleanups no longer replay; Blue Iris v2 events remain visible and preserved. diff --git a/docs/HOME_ASSISTANT.md b/docs/HOME_ASSISTANT.md index a03a681..9bc20b5 100644 --- a/docs/HOME_ASSISTANT.md +++ b/docs/HOME_ASSISTANT.md @@ -35,6 +35,12 @@ The legacy **Enable Whitelist** and IP login-bypass controls are retired. Old configuration values are retained for compatibility but grant no access. The obsolete verifier endpoint returns HTTP 410 to authenticated callers. +From v0.1.61, an authenticated display image request with an out-of-range image +ID returns HTTP 404 without querying images. Missing images, reads outside the +camera scope, and reads older than 24 hours also return 404. Missing, expired, +revoked or invalid credentials still return 401. An unavailable image does not +prevent the display from listing the read or refreshing other images. + ## Verification `test/home-assistant-display.test.mjs` checks credential isolation and policy diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 7e87bd7..0732eea 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -64,7 +64,7 @@ Clone the canonical repository and detach at the exact stable release tag: ```bash git clone https://github.com/prsmith777/ALPR-Database-Community.git cd ALPR-Database-Community -git checkout --detach v0.1.60 +git checkout --detach v0.1.61 ./alpr-community install ``` diff --git a/docs/UPDATES.md b/docs/UPDATES.md index 9104e76..f25af49 100644 --- a/docs/UPDATES.md +++ b/docs/UPDATES.md @@ -47,7 +47,7 @@ shown on the GitHub Releases page, rather than deploying moving `main`: ```bash git clone https://github.com/prsmith777/ALPR-Database-Community.git cd ALPR-Database-Community -git checkout --detach v0.1.60 +git checkout --detach v0.1.61 ./alpr-community install ``` @@ -88,7 +88,7 @@ alpr_native_update() ( set -Eeuo pipefail download_dir="$(mktemp -d /tmp/alpr-maintenance-download.XXXXXX)" trap 'rm -rf -- "$download_dir"' EXIT - asset_base="https://github.com/prsmith777/ALPR-Database-Community/releases/download/v0.1.60" + asset_base="https://github.com/prsmith777/ALPR-Database-Community/releases/download/v0.1.61" curl -fLsS --retry 3 "$asset_base/community-maintenance.sh" -o "$download_dir/community-maintenance.sh" curl -fLsS --retry 3 "$asset_base/community-maintenance.sh.sha256" -o "$download_dir/community-maintenance.sh.sha256" (cd "$download_dir" && sha256sum --check --strict community-maintenance.sh.sha256) @@ -99,7 +99,7 @@ unset -f alpr_native_update ``` The launcher verifies the canonical repository and exact released tag, loads the -fixed tools outside your checkout, and asks for **INSTALL v0.1.60**. It uses the +fixed tools outside your checkout, and asks for **INSTALL v0.1.61**. It uses the same guarded backup/install workflow and does not reset or reinstall your system. It temporarily stops only this installation's matching per-user systemd update agent, then restarts it with the installed code. Keep the terminal open and do @@ -372,6 +372,12 @@ ALPR_UPDATE_CLEANUP=ALPR_UPDATE_CLEANUP These acknowledgements prevent an unattended typo from installing, accepting, rolling back, or deleting rollback assets. They are not passwords. +## v0.1.61: Home Assistant image validation + +Use the normal update workflow. Oversized display image IDs now return HTTP 404 +instead of HTTP 503. Existing display links continue to use their saved camera +scope, expiration and revocation settings. This patch adds no database migrations. + ## v0.1.60: tracked migration transition Existing installations use the normal Windows or Linux update workflow. A direct diff --git a/lib/help-manual.mjs b/lib/help-manual.mjs index 319b3f2..f6ba59e 100644 --- a/lib/help-manual.mjs +++ b/lib/help-manual.mjs @@ -12,7 +12,7 @@ export const HELP_MANUAL = Object.freeze({ title: "ALPR Database Community User Guide", shortTitle: "User Guide", description: "A practical guide to using, configuring, and safely administering the portable Community application.", - manualVersion: "3.28", + manualVersion: "3.29", updatedAt: "November 2, 2026", coverageBaseline: "Published clean-history Community release with portable configuration and no private deployment controls.", filename: "ALPR-Database-Community-User-Guide.pdf", @@ -560,7 +560,7 @@ export const HELP_MANUAL = Object.freeze({ "Open Settings > Home Assistant. The legacy IP whitelist is retired and cannot bypass authentication.", "Enter a display name and the exact Home Assistant origin, including http:// or https:// and the port. Dashboard paths and wildcards are not accepted.", "Choose one camera or all cameras, then choose an expiration of 1 to 90 days. Create the link and copy it immediately into a Home Assistant webpage card. The credential is displayed once; keep it private.", - "The display shows up to 25 recent reads and their images from the last 24 hours. It cannot open settings, modify records, use normal application APIs or create an administrator session.", + "The display shows up to 25 recent reads and their images from the last 24 hours. A read can remain listed when its image is unavailable. The display cannot open settings, modify records, use normal application APIs or create an administrator session.", "Use HTTPS for ALPR when Home Assistant uses HTTPS. Display credentials do not depend on third-party cookies. Access from an unapproved iframe origin is blocked.", "Revoke a display to stop subsequent data and image requests. The display clears on its next refresh; information already viewed cannot be recalled. A normal browser still requires ALPR login.", ], diff --git a/lib/home-assistant-display.mjs b/lib/home-assistant-display.mjs index c750eea..79bf330 100644 --- a/lib/home-assistant-display.mjs +++ b/lib/home-assistant-display.mjs @@ -78,7 +78,9 @@ export class HomeAssistantDisplayService { return { label: grant.label, reads: result.rows }; } async imagePath(grant, readId) { - if (!/^[1-9]\d{0,9}$/.test(String(readId || ""))) return null; + // plate_reads.id is a PostgreSQL integer; reject overflow before binding it. + const value = String(readId ?? ""); + if (!/^[1-9]\d{0,9}$/.test(value) || Number(value) > 2_147_483_647) return null; const result = await this.pool.query(`SELECT COALESCE(vehicle_image_path,image_path) AS path FROM public.plate_reads WHERE id = $1 AND ($2::text IS NULL OR camera_name = $2) AND timestamp > CURRENT_TIMESTAMP - INTERVAL '24 hours'`, [readId, grant.cameraName]); diff --git a/lib/release-info.mjs b/lib/release-info.mjs index b6e62cc..05cada7 100644 --- a/lib/release-info.mjs +++ b/lib/release-info.mjs @@ -4,15 +4,12 @@ import builtReleaseMetadata from "./built-release-metadata.mjs"; import { HELP_MANUAL } from "./help-manual.mjs"; export const CURRENT_RELEASE_NOTES = Object.freeze({ - title: "Reliable upgrades, Blue Iris setup and Home Assistant displays", + title: "Home Assistant display image validation", publishedAt: "2026-11-02", items: Object.freeze([ - "Apply only pending database migrations, verify their checksums, and adopt existing completion markers without replaying historical cleanup.", - "Preserve Blue Iris v2 direction observations and expose them to current-direction queries while retaining backup, row-count validation and rollback.", - "Bind ALPR camera aliases to explicit Blue Iris recording short IDs, refresh camera inventory in setup, and use the saved binding in automatic vehicle processing.", - "Show separate Blue Iris alert and ALPR read tolerances and require an explicit image owner when several ALPR reads match.", - "Create revocable, expiring, camera-scoped read-only Home Assistant display links with exact parent-origin restrictions; retire the inactive IP login-bypass controls.", - "Update User Guide 3.28, release and installation guidance. Existing installations use their normal update workflow without manual SQL or an intermediate release.", + "Return HTTP 404 for oversized Home Assistant display image IDs before querying images, replacing the previous HTTP 503 response.", + "Preserve read-only display access, camera scope, expiration, revocation and exact parent-origin restrictions.", + "Add integer-boundary unit, PostgreSQL and production-browser regression coverage; update User Guide 3.29. This patch adds no database migrations and uses the normal update workflow.", ]), }); diff --git a/package.json b/package.json index 68ddcd5..fd75292 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blueiris-alpr-database", - "version": "0.1.60", + "version": "0.1.61", "private": true, "engines": { "node": ">=24.0.0 <25" diff --git a/scripts/test-community-browser.mjs b/scripts/test-community-browser.mjs index 85fdbb0..0462793 100644 --- a/scripts/test-community-browser.mjs +++ b/scripts/test-community-browser.mjs @@ -73,6 +73,11 @@ export async function exerciseBrowser(config) { assert.notEqual(shell.headers.get("x-frame-options"),"DENY"); assert.ok(shell.headers.get("content-security-policy").includes(`frame-ancestors ${parentOrigin};`)); assert.equal((await fetch(origin+`/api/home-assistant/display/${grant.id}`)).status,401); + for (const readId of ["2147483648", "9999999999"]) { + const missing = await fetch(origin+`/api/home-assistant/display/${grant.id}/image/${readId}`,{headers:{Authorization:"Bearer "+grant.token}}); + assert.equal(missing.status,404,"Out-of-range display image IDs are unavailable, not server errors"); + assert.equal(missing.headers.get("cache-control"),"no-store, private"); + } assert.equal((await fetch(origin+"/api/current-access",{headers:{Authorization:"Bearer "+grant.token}})).status,401); const normal=await fetch(origin+"/login");assert.equal(normal.headers.get("x-frame-options"),"DENY"); browser=await chromium.launch({executablePath,headless:true}); diff --git a/scripts/test-community-bugfixes-postgres.mjs b/scripts/test-community-bugfixes-postgres.mjs index f1c7707..580f14a 100644 --- a/scripts/test-community-bugfixes-postgres.mjs +++ b/scripts/test-community-bugfixes-postgres.mjs @@ -111,6 +111,11 @@ export async function exerciseCommunityBugfixes(server, { browserTest } = {}) { assert.equal(await displays.imagePath(auth,other.id),null); const handler = createDisplayReadHandler({service:displays,readImage:async()=>Buffer.from("fixture-image")}); assert.equal((await handler(new Request("http://fixture",{headers:{authorization:"Bearer "+grant.token}}),{params:{grantId:grant.id,readId:read.id}})).status,200); + for (const readId of ["2147483647", "2147483648", "9999999999"]) { + const missing = await handler(new Request("http://fixture",{headers:{authorization:"Bearer "+grant.token}}),{params:{grantId:grant.id,readId}}); + assert.equal(missing.status,404,"Unknown or out-of-range image ID: "+readId); + assert.equal(missing.headers.get("cache-control"),"no-store, private"); + } await displays.revoke(grant.id); assert.equal(await displays.authorize(grant.id,"Bearer "+grant.token),null); assert.equal(await displays.publicGrant(grant.id),null); diff --git a/test/help-manual.test.mjs b/test/help-manual.test.mjs index 8599bd4..c675fff 100644 --- a/test/help-manual.test.mjs +++ b/test/help-manual.test.mjs @@ -18,7 +18,7 @@ async function source(path) { } test("the user guide is structured, searchable, and role-aware", () => { - assert.equal(HELP_MANUAL.manualVersion, "3.28"); + assert.equal(HELP_MANUAL.manualVersion, "3.29"); assert.ok(HELP_MANUAL.sections.length >= 24); const ids = HELP_MANUAL.sections.map((section) => section.id); diff --git a/test/home-assistant-display.test.mjs b/test/home-assistant-display.test.mjs index 19eca8c..80a3cfd 100644 --- a/test/home-assistant-display.test.mjs +++ b/test/home-assistant-display.test.mjs @@ -40,3 +40,24 @@ test("unauthorized image requests never read storage or execute the data query", const handler = createDisplayReadHandler({service:{authorize:async()=>null, imagePath:()=>assert.fail("unexpected data access")},readImage:()=>assert.fail("unexpected storage access")}); assert.equal((await handler(new Request("http://alpr.invalid"),{params:{grantId:id,readId:"1"}})).status,401); }); + +test("oversized display image IDs return 404 without querying images or storage", async () => { + const service = new HomeAssistantDisplayService({ query: async () => assert.fail("Invalid image IDs must not reach PostgreSQL") }); + service.authorize = async () => ({ id, label: "Display", cameraName: "Camera" }); + const handler = createDisplayReadHandler({ service, readImage: async () => assert.fail("Invalid image IDs must not read storage") }); + for (const readId of ["2147483648", "9999999999", "99999999999999999999"]) { + const response = await handler(new Request("http://alpr.invalid"), { params: { grantId: id, readId } }); + assert.equal(response.status, 404, readId); + assert.equal(response.headers.get("cache-control"), "no-store, private"); + assert.equal((await response.arrayBuffer()).byteLength, 0); + } +}); + +test("display image lookup accepts the positive PostgreSQL integer boundary", async () => { + const calls = []; + const service = new HomeAssistantDisplayService({ query: async (_sql, values) => { calls.push(values); return { rows: [] }; } }); + const grant = { cameraName: "Camera" }; + assert.equal(await service.imagePath(grant, "2147483647"), null); + assert.equal(await service.imagePath(grant, "1"), null); + assert.deepEqual(calls, [["2147483647", "Camera"], ["1", "Camera"]]); +}); diff --git a/test/release-info.test.mjs b/test/release-info.test.mjs index 877e263..72203d6 100644 --- a/test/release-info.test.mjs +++ b/test/release-info.test.mjs @@ -23,8 +23,8 @@ test("release information resolves a commit-pinned deployment image", () => { ALPR_RELEASE_CHANNEL: "staging", }); - assert.equal(release.version, "0.1.60"); - assert.equal(release.manualVersion, "3.28"); + assert.equal(release.version, "0.1.61"); + assert.equal(release.manualVersion, "3.29"); assert.equal(release.manualUpdatedAt, "November 2, 2026"); assert.equal(release.gitSha, "8cd2fa8"); assert.equal(release.channel, "staging"); @@ -32,20 +32,19 @@ test("release information resolves a commit-pinned deployment image", () => { assert.equal(release.readOnly, true); assert.equal( release.notes.title, - "Reliable upgrades, Blue Iris setup and Home Assistant displays" + "Home Assistant display image validation" ); assert.equal(release.notes.publishedAt, "2026-11-02"); assert.ok(release.notes.items.length >= 3); const notes = release.notes.items.join(" "); - assert.match(notes, /pending database migrations/); - assert.match(notes, /checksums/); - assert.match(notes, /Blue Iris v2 direction observations/); - assert.match(notes, /row-count validation and rollback/); - assert.match(notes, /recording short IDs/); - assert.match(notes, /explicit image owner/); - assert.match(notes, /read-only Home Assistant/); + assert.match(notes, /HTTP 404/); + assert.match(notes, /oversized Home Assistant display image IDs/); + assert.match(notes, /before querying images/); + assert.match(notes, /read-only display access/); + assert.match(notes, /camera scope, expiration, revocation/); assert.match(notes, /parent-origin restrictions/); - assert.match(notes, /User Guide 3\.28/); + assert.match(notes, /no database migrations/); + assert.match(notes, /User Guide 3\.29/); });