Skip to content

fix(apiv2): refuse malformed dates in item metadata edits - #2810

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Tobechukwu-Njoku:fix/admin-metadata-date-validation
Oct 29, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Tobechukwu-Njoku:fix/admin-metadata-date-validation

Conversation

@Tobechukwu-Njoku

@Tobechukwu-Njoku Tobechukwu-Njoku commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Tobechukwu Njoku

Problem

Related issue: #2277
Validation tasks: none

PATCH /api/v2/admin/items/{id}/metadata passes its date members to the database as text. An empty or malformed release_date, or a season or episode air_date, makes PostgreSQL reject the write, and the request answers 500 internal_error. The same value in first_air_date or last_air_date, which are text columns, is stored as given: "2024-13-01" is saved and comes back on the item. With this change the handler refuses any of the four that isn't a YYYY-MM-DD date with 422 validation_failed naming the member.

This is the first half of #2277. The second half, refusing null on members that can't be cleared, is not in this PR (see Approach), so the issue stays open.

Approach

The v2 handler checks release_date, first_air_date, last_air_date and air_date before it calls the metadata service. A value must parse as a YYYY-MM-DD calendar date with a year of 1 or later (PostgreSQL's date has no year 0). Anything else, including the empty string, is 422 validation_failed with an invalid error at body.<member> for each bad member, and nothing is written. null still clears these dates and omission still leaves them alone. The request schema is unchanged; docs/admin-catalog-api.md states the rule. The check sits in the v2 handler, so frozen v1 behaves as before.

Refusing null on members that can't be cleared (title, year, genres, and so on) means dropping nullable from those members of AdminItemMetadataUpdate. That narrows the v2 request schema, which make verify-apiv2-contract treats as breaking, so it needs a maintainer's breaking-change approval before anyone builds it. Until then null on those members still returns 200 and changes nothing.

Validation

  • Live check on a local server and database, main 9e81ab0 and then this branch at 6ad3711, sending the same requests to the same movie, series, season and episode (excerpts under Evidence). On main, a malformed release_date or season or episode air_date returns 500, and a malformed first_air_date or last_air_date returns 200 and is stored. On this branch each of them returns 422 at the member, and valid dates and null still return 200.
  • New handler test: one request sends a bad value for each of the four date members (an empty string, 2024-02-30, 0000-01-01, an RFC 3339 timestamp) and gets one invalid error per member, with nothing reaching the service; a second checks that a real date passes and null still clears. Without the check it fails with 200.
  • go build ./..., gofmt, go vet ./... and make lint-changed are clean. make test-go passes apart from three tests that fail the same way on main 9e81ab0 in this environment (two jellycompat PlaybackInfo tests and TestProvider_DirectoryListingFollowsChanges in metadata/nfo). internal/apiv2 and one api/handlers timing test failed under machine load in the parallel run and pass when run on their own.

Evidence

PATCH /api/v2/admin/items/{id}/metadata on a local server and database, with the same items and requests in the order shown: before on main 9e81ab0, after on this branch at 6ad3711. "Stored as" is the column value read back from PostgreSQL.

Movie (release_date, first_air_date), before:

PATCH {"first_air_date":"2024-13-01"} -> 200 (stored as '2024-13-01')
PATCH {"release_date":""}             -> 500 internal_error
PATCH {"release_date":"not-a-date"}   -> 500 internal_error
PATCH {"release_date":"1995-02-30"}   -> 500 internal_error
PATCH {"release_date":"1995-12-15"}   -> 200 release_date "1995-12-15"
PATCH {"release_date":null}           -> 200 release_date null

After:

PATCH {"first_air_date":"2024-13-01"} -> 422 validation_failed at body.first_air_date: expected a calendar date, YYYY-MM-DD
PATCH {"release_date":""}             -> 422 validation_failed at body.release_date: expected a calendar date, YYYY-MM-DD
PATCH {"release_date":"not-a-date"}   -> 422 validation_failed at body.release_date: expected a calendar date, YYYY-MM-DD
PATCH {"release_date":"1995-02-30"}   -> 422 validation_failed at body.release_date: expected a calendar date, YYYY-MM-DD
PATCH {"release_date":"1995-12-15"}   -> 200 release_date "1995-12-15"
PATCH {"release_date":null}           -> 200 release_date null

Series (last_air_date), season and episode (air_date), before:

series  PATCH {"last_air_date":"2024-13-01"}   -> 200 (stored as '2024-13-01')
series  PATCH {"last_air_date":""}             -> 200 (stored as '')
series  PATCH {"last_air_date":"2024-03-15"}   -> 200 (stored as '2024-03-15')
series  PATCH {"last_air_date":null}           -> 200 (stored as NULL)
season  PATCH {"air_date":""}                  -> 500 internal_error
season  PATCH {"air_date":"2020-02-30"}        -> 500 internal_error
season  PATCH {"air_date":"2020-01-10"}        -> 200 (stored as '2020-01-10')
season  PATCH {"air_date":null}                -> 200 (stored as NULL)
episode PATCH {"air_date":""}                  -> 500 internal_error
episode PATCH {"air_date":"not-a-date"}        -> 500 internal_error
episode PATCH {"air_date":"2020-01-17"}        -> 200 (stored as '2020-01-17')
episode PATCH {"air_date":null}                -> 200 (stored as NULL)

After:

series  PATCH {"last_air_date":"2024-13-01"}   -> 422 validation_failed at body.last_air_date: expected a calendar date, YYYY-MM-DD
series  PATCH {"last_air_date":""}             -> 422 validation_failed at body.last_air_date: expected a calendar date, YYYY-MM-DD
series  PATCH {"last_air_date":"2024-03-15"}   -> 200 (stored as '2024-03-15')
series  PATCH {"last_air_date":null}           -> 200 (stored as NULL)
season  PATCH {"air_date":""}                  -> 422 validation_failed at body.air_date: expected a calendar date, YYYY-MM-DD
season  PATCH {"air_date":"2020-02-30"}        -> 422 validation_failed at body.air_date: expected a calendar date, YYYY-MM-DD
season  PATCH {"air_date":"2020-01-10"}        -> 200 (stored as '2020-01-10')
season  PATCH {"air_date":null}                -> 200 (stored as NULL)
episode PATCH {"air_date":""}                  -> 422 validation_failed at body.air_date: expected a calendar date, YYYY-MM-DD
episode PATCH {"air_date":"not-a-date"}        -> 422 validation_failed at body.air_date: expected a calendar date, YYYY-MM-DD
episode PATCH {"air_date":"2020-01-17"}        -> 200 (stored as '2020-01-17')
episode PATCH {"air_date":null}                -> 200 (stored as NULL)

Risks

A v2 client that sent "" or another non-date string in first_air_date or last_air_date used to get 200 with the string stored; it now gets 422. The API contract already says date-only values are YYYY-MM-DD, and the web metadata dialog sends either a YYYY-MM-DD date from a date input or null, so it is not affected. No schema, fixture or v1 change.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (Claude desktop app)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5 (Ultracode)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a

Note

Reject malformed YYYY-MM-DD dates in apiv2 item metadata edits

Adds rejectMalformedMetadataDates validation before the metadata service call in the admin item metadata update handler. Non-null date members (release, first-air, last-air, air) must parse as valid YYYY-MM-DD calendar dates with year >= 1; failures return a 422 validation error per member and no write occurs. Null dates are still skipped and cleared. Tests cover empty, impossible, year-0, and timestamp-formatted values in admin_catalog_item_metadata_test.go; docs updated in admin-catalog-api.md.

  • Behavioral Change: requests that previously passed malformed dates to the service now fail with 422; frozen v1 is unchanged and still treats null like omission

Macroscope summarized 60dee0d.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b0484941-2e58-4de2-9f16-811c0c17201e
Commits

Reviewing files that changed from the base of the PR and between f9c41c1 and 60dee0d.

Files selected for processing: 2
  • docs/admin-catalog-api.md
  • internal/apiv2/admin_catalog_item_metadata_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

Admin catalog metadata updates now validate supported date fields before calling the metadata service. Invalid dates return field-specific validation errors. Null date values remain valid and clear the field.

Changes: Metadata date validation

Layer / File(s) Summary
Validate metadata dates
internal/apiv2/admin_catalog_item_metadata.go, internal/apiv2/admin_catalog_item_metadata_test.go, docs/admin-catalog-api.md
The update handler validates non-null date values as YYYY-MM-DD dates with a year of at least 1. Invalid values produce field-specific validation errors and prevent the service call. Tests cover invalid dates, a valid leap day, and clearing a date with null. The API documentation describes the validation and frozen v1 behavior.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Silo-Server/silo-server#2277: The reported malformed and empty date inputs returning 500 are addressed by validation that returns 422 before the metadata service runs. The request to reject null for other members is not covered.

Possibly related PRs

Suggested reviewers: quick104

Merge Risk: Minimal · up to 60dee

The documented v2 date-validation behavior is implemented and covered across the handler and transport tests, with no actionable merge-blocking risk identified.

Security architecture risk: Minimal · up to 60dee

The change rejects malformed dates before any metadata write while preserving existing permissions, valid updates, and explicit date clears. No material security risk was found introduced or worsened by this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed behavior is confined to date inputs on the existing authorized catalog metadata PATCH operation. It narrows values reaching item, season, and episode persistence without adding caller authority, another service destination, or a new persistence owner.

Trust Boundaries and Controls

  • observed — The route retains its metadata-curation permission gate. Production controls authenticate the caller, check enabled identity and permission, resolve target libraries, and enforce applicable library scope before dispatching to the handler. Date validation does not bypass those controls.

Resilience and Maintainability Implications

  • observed — Malformed requests now terminate before mutation, including when other valid edits accompany an invalid date. Accepted updates retain existing transactional containment: media-item writes group dependent work in a transaction, and episode writes commit derived series dates with the episode change. No new mutable state or cleanup obligation is added by validation.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: rejecting malformed dates in API v2 item metadata edits.
Description check Passed The description directly explains the date-validation behavior, affected fields, error responses, tests, documentation, and scope of the changes.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 20, 2026
@silo-kody

silo-kody Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 20, 2026

Copy link
Copy Markdown

The API excerpts show the new 422 behavior for release_date and first_air_date, but do not show it for every date member or identify the exact API surface and capture commit.

  • last_air_date: add before-and-after API response excerpts for a malformed value.
  • Season/episode air_date: add before-and-after API response excerpts for a malformed value.

Include PATCH /api/v2/admin/items/{id}/metadata and the base/head commit identifiers with those excerpts.

Suggested fix: No diff.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 20, 2026
@Tobechukwu-Njoku

Copy link
Copy Markdown
Contributor Author

Added before/after excerpts for last_air_date and for season and episode air_date, next to the movie ones. All are PATCH /api/v2/admin/items/{id}/metadata, before on main 9e81ab0 and after on this branch at 6ad3711.

@silo-kody

silo-kody Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Tobechukwu-Njoku and others added 2 commits October 29, 2026 00:31
PATCH /api/v2/admin/items/{id}/metadata passed date members to the
repositories as text. An empty or malformed release_date or air_date
failed the write in PostgreSQL and the request answered 500
internal_error; the same value in first_air_date or last_air_date (text
columns) was stored as given.

The handler now checks the four date members before calling the
service: a value must be a YYYY-MM-DD calendar date, and anything else
is 422 validation_failed at body.<member>, with every bad member named
and nothing written. Null still clears these dates. Frozen v1 is
unchanged.

Refusing null on members that can't be cleared, the other half of the
issue, narrows the v2 request schema and is left for a separate change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…date test

CONTRIBUTING's "Decide what to test" counts several bad inputs that reach
the same error path as one case. One request now sends a bad value for
each of the four date members, including year 0 (which time.Parse
accepts and PostgreSQL rejects), and checks that every member is named
and nothing reaches the service; a second checks that a real date passes
and null still clears.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Tobechukwu-Njoku
Tobechukwu-Njoku force-pushed the fix/admin-metadata-date-validation branch from f9c41c1 to 60dee0d Compare October 29, 2026 01:10
@silo-kody

silo-kody Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 60dee0d562e2ae4b748c26afbd2ae1dcc85b833f. No actionable findings.

The focused metadata transport and date-validation tests pass. The new malformed-date test fails against the merge base with HTTP 200 instead of 422. The validation runs before persistence and preserves null clearing and frozen v1 behavior.

Validation tasks: none. No passed-case impact was found in the live validation issue records. Direct board enumeration was unavailable because the review credential lacks read:project; this was not an exhaustive board check.

Reviewed with Codex (gpt-6.1-sol), using independent xhigh review and verification passes.

@Quick104
Quick104 merged commit 9b0e8a3 into Silo-Server:main Oct 29, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants