Skip to content

Fix QR object-URL leak, asset status filtering and frontend security headers - #1858

Merged
yusuftomilola merged 10 commits into
DistinctCodes:mainfrom
akargi:feature/frontend-security-and-status-alignment
Nov 24, 2026
Merged

yusuftomilola merged 10 commits into
DistinctCodes:mainfrom
akargi:feature/frontend-security-and-status-alignment

Conversation

@akargi

@akargi akargi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes four frontend security/status-alignment issues.

#1781 — useAssetQr never revoked its object URL

  • frontend/hooks/useAssetQr.ts now tracks the currently published blob URL in a ref and revokes it when the effect for an asset is torn down (asset change or unmount), including when the request is cancelled. The URL is cleared from rendered state before being revoked, so no <img> is left pointing at a revoked URL, and superseded requests never create a URL at all.
  • Added frontend/hooks/useAssetQr.test.ts with mocked URL.createObjectURL / URL.revokeObjectURL and @/lib/api, covering publish, revoke on unmount, revoke on assetId change, and cancellation before resolve.

#1780 — Asset status aliases: form sends canonical, list filters raw

  • Revalidated against current main: the real gap was the backend query contract, not the frontend enum.
  • backend/src/assets/dto/list-assets-query.dto.ts now validates status with @IsIn(Object.values(AssetStatusInput)) after a @Transform that trims/uppercases the value. Canonical statuses plus the ACTIVE / MAINTENANCE aliases are accepted; unknown values are rejected with a 400.
  • backend/src/assets/assets.service.ts::findAll now resolves the status through this.lifecycle.normalizeStatus(query.status) before binding :st, mirroring updateStatus, so aliases filter on the canonical stored value.
  • Extended list-assets-query.dto.spec.ts and added assets.status-filter.spec.ts proving every canonical value and alias filters on the matching AssetStatus.
  • Aligned the remaining UI alias usage in frontend/features/Dashboard/DashboardCharts.tsx (ACTIVE → AVAILABLE, MAINTENANCE → IN_MAINTENANCE). The assets list filter already sends canonical values.

#1778 — CSP hard-coded localhost:6003

  • frontend/next.config.ts builds connect-src at build time from the origins of NEXT_PUBLIC_API_URL and NEXT_PUBLIC_WS_URL, keeping 'self' and the Stellar/Soroban testnet endpoints. Localhost origins are only emitted in development and are stripped from production builds. 'unsafe-eval' is development-only. All other headers are unchanged.
  • Added frontend/__tests__/next-config-headers.test.ts covering configured origins, localhost removal in production, dev-only allowances, and header stability.

#1776 — Permissions-Policy disabled the camera

  • Changed the production header to camera=(self), microphone=(), geolocation=() so the QR scanner's getUserMedia works from the same origin, while microphone and geolocation remain denied. Extended the config test to assert this.

Testing

Tests were not run locally per the task instructions.

Closes #1781
Closes #1780
Closes #1778
Closes #1776

Track the published blob URL in a ref and release it when the effect for an asset is torn down, clearing rendered state first so no <img> points at a revoked URL. Superseded requests no longer create URLs.
Closes DistinctCodes#1781

Mock URL.createObjectURL/revokeObjectURL and @/lib/api to assert the URL is revoked on unmount, on assetId change, and that cancelled requests never create a URL.
Replace the free-form @IsString status query with a normalized @isin check over AssetStatusInput so canonical values and the ACTIVE/MAINTENANCE aliases are accepted and typos are rejected.
Resolve the query status through AssetLifecycleService.normalizeStatus before binding :st, matching updateStatus and making aliases filter on the canonical stored status.
Closes DistinctCodes#1780

Extend the DTO spec for canonical/alias/lower-case/unknown statuses and add a findAll spec proving each input filters on the canonical AssetStatus.
Replace the stale ACTIVE/MAINTENANCE enum members with AVAILABLE/IN_MAINTENANCE so report colors match the canonical statuses returned by the API.
Derive connect-src from NEXT_PUBLIC_API_URL and NEXT_PUBLIC_WS_URL at build time, keep 'self' and the Stellar/Soroban testnet endpoints, drop localhost origins from production builds and remove 'unsafe-eval' outside development. All other headers are unchanged.
Closes DistinctCodes#1778

Add a next.config test asserting configured API/WS origins appear in connect-src, localhost and unsafe-eval never ship in production, dev keeps them, and unrelated headers stay intact.
Change camera=() to camera=(self) so the QR scanner's getUserMedia call works with production headers; microphone and geolocation remain denied.
Closes DistinctCodes#1776

Verify the production Permissions-Policy header keeps camera=(self) while microphone and geolocation stay denied.
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@akargi is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Nov 23, 2026

Copy link
Copy Markdown

@akargi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@yusuftomilola
yusuftomilola merged commit 0bc1eec into DistinctCodes:main Nov 24, 2026
1 of 15 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

2 participants