π‘οΈ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Merge pull request #254 from luci-serendipity/fix-first-oidc-owner
Omega (QA)47a85168ec45
diff --cc CHANGELOG.mdindex f598974,f1c2497..b15bb62--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -1,95 -1,12 +1,97 @@@# Changelog-## 1.0.3 - 2026-05-18+## 1.0.4 - Unreleased++- **Claim documents (issue #148):** claims can now carry documents β claim approval or rejection letters, photos of the defect, repair invoices, and similar evidence. Each claim shows a Documents section in the claims view: attach a file directly, or upload it to Paperless-ngx and link it, then view or remove it from the same place. Access follows the warranty's other documents: the owner and admins only, never shared through global view. Deleting a claim or its warranty removes the attached local files from disk; Paperless documents are unlinked, never deleted from Paperless.+ - _Files: `backend/migrations/052_create_claim_documents_table.sql`, `backend/warranties_routes.py`, `backend/file_routes.py`, `frontend/js/components/claims.js`, `frontend/style.css`, `locales/en/translation.json`_+- **Void warranty status (issue #250):** a warranty can now be manually terminated ("voided") when its conditions are broken before the expiration date β physical damage, unauthorized repairs, broken seals β without deleting the item or changing its expiration date. Voided warranties stay in the list with a Void status (with a matching filter on the main page and the status dashboard, plus a Void count card), and are excluded from the Total Value card, active/expired/expiring counts, expiration timelines, and expiry notification emails. Voiding is reversible from the same card actions.+ - _Files: `backend/migrations/053_add_voided_at_to_warranties.sql`, `backend/warranties_routes.py`, `backend/statistics_routes.py`, `backend/notifications.py`, `frontend/js/components/warrantyActions.js`, `frontend/js/components/warrantyRenderer.js`, `frontend/js/controllers/warrantyListController.js`, `frontend/js/lib/warrantyProcessing.js`, `frontend/script.js`, `frontend/index.html`, `frontend/status.js`, `frontend/status.html`, `frontend/style.css`, `locales/en/translation.json`_+- **Paperless document titles use the product name (issue #147):** documents uploaded to Paperless-ngx were titled "Warracker invoice - <filename>", which says nothing about the product. They are now titled after the warranty's product name β "<Product> - Invoice", "<Product> - Manual", and "<Product> - Claim document" for claim attachments. The old title format remains only as a fallback when no product name is available.+ - _Files: `frontend/script.js`, `frontend/js/components/paperless.js`, `frontend/js/components/claims.js`_+- **Skip the login screen in OIDC-only mode (issue #186):** a new "Skip Login Screen" setting (admin settings, or the `OIDC_SKIP_LOGIN_SCREEN` environment variable) makes the login page redirect straight to the identity provider when OIDC-only mode is on, instead of showing the "Login with SSO" button screen. If the provider sends the user back with an error, the login screen is shown with the error and the button for a manual retry β the redirect never loops.+ - _Files: `backend/oidc_handler.py`, `backend/admin_routes.py`, `frontend/login.html`, `frontend/settings-new.html`, `frontend/settings-new.js`, `locales/en/translation.json`, `Docker/.env.example`_+- **Dependency and runtime updates:** flask-cors 4.0.2 β 6.0.5, fixing four published CORS policy-bypass vulnerabilities in the old version (CVE-2024-6221, CVE-2024-6866, CVE-2024-6839, CVE-2024-6844). Authlib 1.8.0 β 1.9.1 and PyJWT 2.15.0 β 2.15.1 bring the OIDC/JWT libraries to their current patch releases, and setuptools moves to 84.0.0. The Docker base image moves from Python 3.13 to Python 3.15.+ - _Files: `backend/requirements.txt`, `Dockerfile`_+- **Paperless-ngx document access control (security, GHSA-fv62-3hrm-gf83 / GHSA-3h89-rqfj-5674):** Warracker connects to Paperless-ngx with one shared API token, and any signed-in user could list every document in the instance, link another user's document to their own warranty or claim, and then download it β the link itself was treated as proof of ownership. Warracker now tracks which user owns each Paperless document (recorded when a document is uploaded through Warracker or first linked; existing links are backfilled by migration). Search results are scoped to the requesting user, linking a document owned by someone else is rejected in warranty create/update, search-and-link, and claim documents, downloads follow ownership plus the usual global-view rules for shared document types, and the Paperless debug endpoints are admin-only. Claim document metadata (filenames and linked document ids) is also no longer shown to global-view readers β claim documents are owner/admin-only, as their contents already were.+ - _Files: `backend/migrations/054_create_paperless_document_ownership.sql`, `backend/paperless_access.py`, `backend/file_routes.py`, `backend/warranties_routes.py`_+- **Stored XSS via Paperless document titles (security):** the Paperless document browser rendered document titles, correspondents, and tag names into the page without escaping, so a document titled with HTML/JavaScript executed in the browser of anyone who opened the browser view β admins included. These fields are now HTML-escaped before rendering.+ - _Files: `frontend/js/components/paperless.js`_+- **Known default JWT secret removed from the compose files (security):** both shipped docker-compose files defaulted `SECRET_KEY` to a fixed value printed in this public repository, so an install that never set its own key signed its login tokens with a secret anyone could read β enough to forge an admin session. The compose default is now empty, which activates the backend's existing behavior of generating a random key and persisting it to a file; setting `SECRET_KEY` explicitly still takes precedence.+ - _Files: `docker-compose.yml`, `Docker/docker-compose.yml`, `Docker/.env.example`_+- **Total Value card undercounted warranties with no currency set:** since 1.0.3 the dashboard total has only summed warranties whose stored currency exactly matches the user's default currency (issue #192), which silently dropped every warranty with no currency recorded β older entries and imports without a currency column β so the card could show a single product's price instead of the total. Warranties with no currency set now count as the user's default currency in both the personal and global statistics; warranties priced in a different explicit currency are still excluded, as #192 intended. The card's tooltip now spells out exactly how the total is counted (updated in all 20 locales).+ - _Files: `backend/statistics_routes.py`, `frontend/status.html`, `locales/*/translation.json`_+- **New 1.0.4 strings machine-translated into all 19 non-English locales:** the void status (8 keys), claim documents (10), and OIDC skip-login (2) strings were added to English only, so non-English UIs showed them in English. All 20 keys are now machine-translated (380 entries), with placeholder integrity verified. These are machine translations β native-speaker review is recommended for customer-facing polish.+ - _Files: `locales/*/translation.json`_+- **Paperless browse/link now visible to non-admin users:** the warranty forms read the Paperless enabled flag from the admin-only settings endpoint, which returns 403 for non-admins, so the browse sections and storage radios were hidden from every non-admin user on desktop and mobile β even though Paperless search-and-link itself is user-scoped. A new signed-in endpoint (`GET /api/paperless/status`) exposes only the enabled flag, never the Paperless URL or API token, and both frontend status checks now use it (admin settings remain as fallback).+ - _Files: `backend/file_routes.py`, `frontend/js/components/paperless.js`, `frontend/script.js`_+- **Void status mistranslations corrected:** the machine fill translated "Void" as emptiness in 14 locales (e.g. German "Leere", French "Vide", Russian "ΠΡΡΡΠΎΡΠ°"), so voided cards read as "empty". The status word now reads as voided/invalid in those locales (e.g. German "UngΓΌltig"), and the German and Portuguese void-warranty count labels are corrected as well. These are still unreviewed corrections β native-speaker review is recommended.+ - _Files: `locales/*/translation.json`_++- **First OIDC user now becomes owner (PR #254):** signing in via OIDC as the first user previously granted admin but not owner, startup recovery promoted an ownerless database's first user to owner without admin, and admin-group sync could demote the owner on their next login. The first OIDC user now gets both owner and admin, recovery grants both roles, and the current owner keeps admin access regardless of admin-group membership.++ - _Files: `backend/oidc_handler.py`, `backend/__init__.py`_++## 1.0.3 - 2026-10-02++- **Status page CSV export:** The Export button on the status dashboard was a placeholder that only showed a "not implemented" toast. It now downloads a CSV of the currently displayed (filtered and sorted) warranties, using the same column layout as the main page export so the file can be re-imported.+ - _Files: `frontend/status.js`_+- **Global-view timeline fix:** The expiration timeline chart always fetched `/api/warranties` (current user only), so in global view it silently omitted other users' warranties. It now builds from the already-loaded view data, matching the rest of the dashboard.+ - _Files: `frontend/status.js`_+- **Currency preference now applies to warranty cards:** The settings page promises "the symbol to display for prices", but card prices preferred the per-warranty currency code (backend-stamped `USD`), so changing the preference never updated the cards. Card prices now use the user's display preference; the per-warranty currency remains as the creation default and in exports. New warranties created without an explicit currency now default to the user's preferred currency (matching CSV import) instead of hardcoded `USD`; edits preserve the existing currency when the form sends none.+ - _Files: `frontend/js/components/warrantyRenderer.js`, `frontend/script.js`, `backend/warranties_routes.py`_+- **Settings fixes:** Removed a leftover "temporary debug script" tag (`js/i18n-debug.js`, 404); fixed the currency dropdown defaulting to a blank value for fresh users (option values are codes like `USD`, but the default set `'$'`); removed a duplicated description paragraph under Expiring Soon Days.+ - _Files: `frontend/settings-new.html`, `frontend/settings-new.js`_+- **Tag creation in edit modal:** Creating a brand-new tag from the edit modal's tag dropdown attached it to the hidden add-wizard instead of the warranty being edited. The create-tag action now routes through the context-aware selection handler.+ - _Files: `frontend/js/components/tagManager.js`_### Fixed-- **Expired JWT Broken UI State:** Fixed critical issue where users returning to the app after their JWT expired would see a broken, empty UI instead of being redirected to login.+- **Whitespace-only product names now rejected:** a name of only spaces passed the "required" check and was stored verbatim; create and update now validate the stripped value.+ - _Files: `backend/warranties_routes.py`+- **Oversized CSV fields now return 400 instead of 500:** a single CSV cell over 128KB raised `csv.Error: field larger than field limit`, which fell into the generic import handler as HTTP 500. CSV parse errors now return a clean 400 (`csv_field_too_large`).+ - _Files: `backend/warranties_routes.py`+- **Total Value card no longer sums across currencies (issue #192):** the `/statistics` and `/statistics/global` endpoints summed `purchase_price` across all currencies into one number while the card displays the user's default-currency symbol. Both now filter to the requesting user's default currency (via a backend symbolβcode map mirroring the frontend's `getCurrencyCode()`).+ - _Files: `backend/statistics_routes.py`+- **Overlong serial numbers now return 400 instead of 500:** serials over 255 characters crashed with an unhandled DB error on warranty create and update; both now validate and return `serial_number_too_long`.+ - _Files: `backend/warranties_routes.py`+- **CSV import now validates overlong product names and tolerates short rows:** importing a CSV with a product name over 255 characters previously leaked the raw Postgres error (`value too long for type character varying(255)`); the row is now rejected with the clean `ProductName must be 255 characters or less.` message matching the REST API validation. Rows with fewer cells than headers previously crashed with `Internal processing error: 'NoneType' object has no attribute 'strip'` (DictReader fills missing cells with `None`); all field extractions now guard against `None`.+ - _Files: `backend/warranties_routes.py`+- **Mobile menu consolidated onto `mobile-menu.js` for all pages:** the frontend refactoring removed the duplicate menu code from `script.js`, leaving only settings-new.html loading the shared `mobile-menu.js` β so on main the hamburger button did nothing on the other pages (the shipped 1.0.2 menu, which lived in `script.js`, was unaffected). All pages that render the toggle now load `mobile-menu.js`. Verified by a dedicated mobile QA pass (390px viewport, touch): menu opens/closes via button, overlay, and Escape on every page; nav links navigate; no horizontal overflow; no new JS errors.+ - _Files: `frontend/index.html`, `frontend/status.html`, `frontend/register.html`, `frontend/about.html`, `frontend/reset-password.html`, `frontend/reset-password-request.html`+- **Missing file download 500 fixed:** `GET /api/files/<missing>` returned HTTP 500 because `serve_file` let `send_from_directory`'s NotFound fall into the generic 500 handler. It now checks existence up front and returns a JSON 404 ("File not found"), matching the `/secure-file/` route. Non-owners still get 403 without leaking file existence. Found by the daily QA sweep.+ - _Files: `backend/file_routes.py`+- **Same-second file-upload collision fixed:** stored upload filenames used a second-resolution timestamp only, so two uploads of the same filename within one second shared a storage path and the second overwrote the first. Filenames now include a random suffix (`unique_upload_filename()` helper, applied to invoice/manual/photo/other-document uploads in both add and update). Found by the daily QA sweep.+ - _Files: `backend/warranties_routes.py`+- **Oversized uploads now return HTTP 413 instead of 500/dropped connection:** files over `MAX_CONTENT_LENGTH` raised `RequestEntityTooLarge`, which was swallowed into 500s by the generic `except` blocks in the warranty write endpoints and the `token_required` decorator. Added an app-wide 413 handler returning a JSON error naming the configured limit, and both layers now let HTTP exceptions propagate. Found by the daily QA sweep.+ - _Files: `backend/__init__.py`, `backend/auth_utils.py`, `backend/warranties_routes.py`+- **Tag create/rename 500 on names over 50 characters fixed:** `tags.name` is `varchar(50)`, but neither `POST /api/tags` nor `PUT /api/tags/<id>` validated length, so a 51+ character name escaped as HTTP 500. Both endpoints now return HTTP 400 up front. Found by the daily QA sweep.+ - _Files: `backend/tags_routes.py`+- **`saveThemePreference is not defined` ReferenceError on status.html fixed:** the prefs loader in `script.js` called the global `saveThemePreference()`, which is only defined by the `js/lib/theme.js` ES module loaded on index.html. Every status-page load logged a console error and aborted the prefs sync, so saved filters, expiring-soon days, and date format were never written to localStorage there. The call is now guarded with a `typeof` check. Found by the daily QA sweep.+ - _Files: `frontend/script.js`+- **Login/registration/password-change 500 on passwords over 72 bytes fixed:** bcrypt rejects passwords longer than 72 bytes with `ValueError`, which escaped as HTTP 500 on `/api/auth/login` (and latently on register and the password reset/change endpoints for strong long passwords). All four endpoints now check the byte length up front via a new `is_password_too_long()` helper and return HTTP 400. Found by the daily QA sweep.+ - _Files: `backend/auth_routes.py`, `backend/auth_utils.py`+- **Insecure direct file access via `/api/files/` fixed (reported by Malik Abdullah):** the legacy `/api/files/<path>` route served any uploaded document to any logged-in user with no ownership check and no regard for the admin's document-sharing (`global_view_enabled`) setting β while `/api/secure-file/` on the same files correctly returned 403. Verified live: with sharing disabled, a second account downloaded another user's invoice via `/api/files/` (200) while `/api/secure-file/` returned 403. Both routes now share a single `_check_file_authorization()` helper (owner, admin, or global-view setting), so they can no longer drift apart; `/api/files/` also gained the path-traversal guard. With sharing enabled (the default, intentional for family/team instances) cross-user access still works consistently on both routes. Credit: reported via responsible disclosure by [humidnhefty](https://github.com/humidnhefty) (Malik Abdullah, Lupine Security).+ - _Files: `backend/file_routes.py`+- **Stored XSS via warranty fields fixed (reported by humidnhefty and the CSCE 413 Texas A&M team):** warranty cards rendered `product_name`, `vendor`, `model_number`, `warranty_type`, tag names, serial numbers, and the user display name into `innerHTML` without escaping, so a malicious value (e.g. injected through CSV import) executed JavaScript in every viewer's browser. All user-controlled fields are now HTML-escaped before rendering (quotes included, so attribute contexts are safe too), and `product_url` links now also reject `javascript:`/`data:`/`vbscript:` schemes. Verified with live payloads (`<img onerror>`, `<svg onload>`, attribute breakout, `javascript:` URL, malicious tag name) β all render as inert text. Credit: reported via responsible disclosure by [humidnhefty](https://github.com/humidnhefty) and the CSCE 413 (Texas A&M University) vulnerability-research team β Carrigan Royer, Jayani Singh, Seshadithya Saravanan, Aaditya Srinivasan, Miko Quinones.+ - _Files: `frontend/js/components/warrantyRenderer.js`, `frontend/js/components/claims.js`, `frontend/status.js`_+- **Input validations are now enforced and translated:** three new HTTP 400 validations β product name over 255 chars (was an unhandled DB error β HTTP 500), expiration date before purchase date (was silently accepted), and invalid claim status (was silently coerced) β now return a stable machine-readable `code` (`product_name_too_long`, `expiration_before_purchase`, `invalid_claim_status`; claim-status errors also include `valid_statuses`) alongside the English fallback message. The frontend maps those codes to i18n keys via a new `apiErrorMessage()` helper in `ui.js` (used by the add-warranty form, edit modal, and claims toasts), so error toasts render in the user's language instead of always-English. Two new English keys were added (`messages.product_name_too_long`, `messages.invalid_claim_status`) and machine-translated into all 19 non-English locales with `{{statuses}}` placeholder integrity verified. Also removed the now-unused `safeErrorMessage()` helper from `apiService.js`.+ - _Files: `backend/warranties_routes.py`, `frontend/js/components/ui.js`, `frontend/js/services/apiService.js`, `frontend/js/components/addWarrantyForm.js`, `frontend/js/components/editModal.js`, `frontend/js/components/claims.js`, `locales/*/translation.json`_+- **Expiry-day inconsistency fixed:** a warranty expiring *today* got three different answers β statistics counted it as `expired` (`expiration_date <= today`), the UI showed "expiring" (0 days left), and the notification query excluded it (`expiration_date > today`). All three now agree it is still valid: statistics uses `expiration_date < today` for expired and `>= today` for the active / expiring-soon / timeline buckets, and the expiry notification query includes it (`>= today`).+ - _Files: `backend/statistics_routes.py`, `backend/notifications.py`_+- **CSV tag/serial round-trip fixed:** the frontend export joined tags and serial numbers with spaces while the import splits on commas, so re-importing an export merged multi-tag warranties into a single tag. Export now joins with `", "` to match the import.+ - _Files: `frontend/js/components/importExport.js`_+- **CSV export/import now round-trips all fields:** the export only wrote 13 columns, silently dropping **Notes, Currency, ModelNumber, and WarrantyType** β re-importing an export lost notes and reset currency to the user's default. Both exports (main page and status dashboard) now write 17 columns including those fields, and the importer accepts them: `Notes`, `ModelNumber`, and `WarrantyType` are stored as-is, `Currency` is validated against the supported code list (unknown codes fall back to the user's preferred currency, as before). Unknown-column files are still accepted via the optional-header mechanism.+ - _Files: `frontend/js/components/importExport.js`, `frontend/status.js`, `backend/warranties_routes.py`, `backend/statistics_routes.py`_+- **Tags/serial numbers containing commas now survive CSV round-trip:** export joined multi-value fields with `", "` and the import split naively on commas, so a tag like `sweepC,comma-tag` came back as two tags. Tags and SerialNumber cells are now JSON-encoded on export (`["a","b,c"]`); the importer parses JSON first and falls back to comma-splitting for legacy or hand-written files.+ - _Files: `frontend/js/components/importExport.js`, `frontend/status.js`, `backend/warranties_routes.py`_+- **Missing English i18n keys added and all 19 non-English locales fully translated:** Static analysis of every `t('β¦')` call and `data-i18n` attribute found 66 keys (toast messages, validation errors, claims labels, tag-manager strings, the registration-disabled notice, `actions.view`, the `tags.no_selected` placeholder, and 16 `paperless.*` keys) missing from `locales/en/translation.json`. i18next renders undefined keys as raw key text, so users saw strings like `messages.deleted_successfully` in toasts. All values were taken from the inline English fallbacks already present at the call sites (with `defaultValue` fallbacks added at the call sites for graceful degradation), so default-language UX is unchanged; other languages now fall back to English instead of showing raw keys. Every key in `locales/en/translation.json` (767 keys) was then machine-translated from English (Google Translate) into all 19 non-English locales β 2,015 missing keys in total (ru 173, it 150, most others ~95β98) plus 1,194 strings that existed only as untranslated English β with `{{placeholder}}` integrity verified on every string (22 cases where the engine translated placeholder names like `{{name}}` β `{{nombre}}` were repaired; one Hindi string that dropped `{{count}}` was fixed by hand; a pre-existing Hebrew translation that dropped `{{username}}` was fixed). Short brand/technical terms (Warracker, Paperless-ngx, CSV, OIDC, URLs) were deliberately left as-is. These are machine translations β native-speaker review is recommended before relying on them for customer-facing polish.+ - _Files: `locales/*/translation.json`, `frontend/js/components/editModal.js`, `frontend/js/components/addWarrantyForm.js`, `frontend/js/components/tagManager.js`_+- **Theme init crash on every page loading the classic script:** `script.js` called `initializeTheme()` unguarded on `DOMContentLoaded`, but `js/lib/theme.js` (the only file defining it) is never included as a classic script β it is an ES module loaded only via `js/index.js`. The call threw `initializeTheme is not defined` on about, status, register, and both reset-password pages (and index), which also silently skipped the rest of that init handler (`setupUIEventListeners()`, `setupModalTriggers()`, form wiring). The call is now guarded with `typeof initializeTheme === 'function'`; the visual theme was and is applied by `theme-loader.js` on all pages.+ - _Files: `frontend/script.js`+- **Paperless "Test Connection" ignored unsaved form values:** Clicking "Test Connection" on the settings page with a freshly entered URL and API token always reported "Connection Failed!", even when the Paperless-ngx instance was reachable, because `POST /api/paperless/test` ignored the `url`/`api_token` in the request body and only ever tested the saved site settings. The endpoint now tests the provided values directly when both are present, and falls back to the saved settings otherwise.+ - _Files: `backend/file_routes.py`+- **Font Awesome now served locally (works offline):** The icon font was loaded from the cdnjs CDN, so all UI icons disappeared on offline or restricted networks. Font Awesome Free 7.0.1 (`all.min.css` + webfonts, ~312 KB) is now vendored under `frontend/vendor/fontawesome/` and referenced by all 8 pages; added `font/woff2`, `font/woff`, and `font/ttf` MIME types to `nginx.conf`.+ - _Files: `frontend/vendor/fontawesome/`, `frontend/*.html`, `nginx.conf`_+- **Expired JWT left a broken UI (#225):** Users returning after their JWT expired saw a broken, empty UI instead of being redirected to login.- **Root Cause:** `auth-redirect.js` only checked for the *presence* of `auth_token` in localStorage, not its validity. An expired token was treated as authenticated, causing the UI to render with stale cached data while API calls returned 401.- - **Solution:** Updated `auth-redirect.js` to synchronously decode the JWT payload and verify the `exp` claim before allowing protected pages to load. Expired or malformed tokens are automatically cleared from localStorage and the user is redirected to login.- - Added OIDC SSO bypass for `auth-redirect.html` to prevent redirect loops during SSO token processing.- - _Files: `frontend/auth-redirect.js`, `frontend/sw.js`, `frontend/index.html`, `frontend/status.html`, `frontend/settings-new.html`, `frontend/login.html`, `frontend/register.html`, `frontend/auth-redirect.html`_+ - **Solution:** Two layers β `auth-redirect.js` now synchronously decodes the JWT payload and verifies the `exp` claim before allowing protected pages to load (expired or malformed tokens are cleared and the user is redirected to login), and the API layer (`apiService.js`) now logs out and redirects on any 401 response instead of leaving an empty authenticated-looking UI. Added OIDC SSO bypass for `auth-redirect.html` to prevent redirect loops during SSO token processing.+ - _Files: `frontend/auth-redirect.js`, `frontend/js/services/apiService.js`, `frontend/sw.js`, `frontend/index.html`, `frontend/status.html`, `frontend/settings-new.html`, `frontend/login.html`, `frontend/register.html`, `frontend/auth-redirect.html`_- **Docker Build Failure (Stale Package Versions):** Fixed Dockerfile failing to build due to outdated pinned Debian package versions.- **Root Cause:** Exact version pins for Debian Trixie packages became stale after security updates (e.g., `libcurl4` renamed to `libcurl4t64`, versions bumped with `+deb13u3` suffix).