Repository navigation
feat(jellycompat): sign image tags and accept them without session - #14
Conversation
- HMAC-sign image tags using the configured JWT secret - Serve item/season/episode images via signed tag without requiring a session or cache hit
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughAdds HMAC-signed short image tags, verifies them in ImagesHandler for session-less image proxying, updates mapper/tag generation to use the signer, wires JWT secret through router defaults, extends episode/thumbhash handling and image cache tag API, and adds tests covering tag behavior and handler flows. ChangesSigned Image Tag Feature
Sequence DiagramsequenceDiagram
participant Client
participant ImagesHandler as HandleItemImage
participant Resolver as resolveItemImageURLFromTag
participant Verifier as signedImageTagMatches
participant Signer as imageTagSigner
participant ItemRepo as ItemRepository
Client->>ImagesHandler: GET /Items/{id}/Images?tag=...
ImagesHandler->>Resolver: extract tag, id, imageType
Resolver->>Verifier: request tag verification (seed, metadata)
Verifier->>Signer: Equal(seed,fallbackURL,actual)
Signer-->>Verifier: true/false
alt tag valid
Resolver->>ItemRepo: fetch artwork without session
ItemRepo-->>Resolver: image URL
Resolver-->>ImagesHandler: resolved URL
ImagesHandler-->>Client: proxied image bytes
else tag invalid
Resolver-->>ImagesHandler: error
ImagesHandler-->>Client: upstream compat error
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22bae2f09f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| if tags := imageTagsWithSeed( | ||
| if tags := imageTagsWithSeed(m.imageTagSigner, | ||
| imageTagSeed(item.ContentID, "Primary", compatCardImageSize, firstNonEmpty(item.PosterPath, item.StillPath), item.PosterThumbhash, item.UpdatedAt), |
There was a problem hiding this comment.
Keep episode image tag seeds consistent
For episode rows produced by the batch/direct list paths, the still art is assigned to PosterPath/StillPath but PosterThumbhash is not populated, while the new no-session verifier signs against episode.StillThumbhash in signedImageTagMatches. When an episode has a stored still thumbhash, the tag emitted here omits that value but verification includes it, so after an image-cache miss or server restart /Items/{episode}/Images/Primary?tag=... rejects an otherwise valid signed episode image tag and returns the auth-required path instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/jellycompat/handlers_images.go`:
- Around line 76-83: The branch that serves cached image URLs via
resolveItemImageURLFromTag may return stale cache hits for requests
authenticated via signed tags; update the handler to revalidate the tag before
using a cached URL (or skip cache hits for tag-authenticated requests).
Concretely, in the image request flow (the code calling
resolveItemImageURLFromTag and LookupSized), detect a non-empty tag in the
request (and the tag-authenticated path), then either (a) perform tag signature
validation using the current JWT secret/image seed before attempting to serve
any cached URL, or (b) bypass cache lookup and force fresh resolution when a tag
is present; adjust resolveItemImageURLFromTag or the calling logic to enforce
this so cached URLs aren’t returned for potentially invalidated tags.
In `@internal/jellycompat/image_tag_signer.go`:
- Around line 17-19: newImageTagSigner currently returns an imageTagSigner even
when given an empty secret, which allows JWT verification to be effectively
disabled; change newImageTagSigner to return nil when secret == "" (i.e., treat
a blank secret as "signing disabled") and update call sites that receive
*imageTagSigner to handle a nil signer (preserve existing unsigned fallback
paths) before calling any methods like Sign or Verify on imageTagSigner.
In `@internal/jellycompat/mapping.go`:
- Around line 108-113: The image tag seed currently always uses
item.PosterThumbhash even when firstNonEmpty chose item.StillPath; update the
thumbhash passed to imageTagSeed in the imageTagsWithSeed call so it matches the
selected primary path — i.e., use item.PosterThumbhash when item.PosterPath is
non-empty, otherwise use item.StillThumbhash (the call sites: imageTagsWithSeed,
imageTagSeed, imageTagSigner, firstNonEmpty, and the dto.ImageTags assignment in
itemFromList).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: aaf197d5-2398-4ee5-9aa1-6b4f21df8a75
📒 Files selected for processing (6)
internal/jellycompat/handlers_images.gointernal/jellycompat/image_tag_signer.gointernal/jellycompat/images_test.gointernal/jellycompat/mapping.gointernal/jellycompat/mapping_images_test.gointernal/jellycompat/router.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/jellycompat/handlers_images.go`:
- Around line 79-80: The code is populating the route cache from a signed-tag
request which can make later unauthenticated /Items/{id}/Images/{type} requests
succeed; modify the logic around h.images.RememberSizedUntil(routeID, imageType,
imageURL.URL, imageSize, imageURL.ExpiresAt) so it is NOT called for signed-tag
requests (i.e., when a tag param is present), or alternatively write to a
tag-scoped cache path instead; ensure the guard checks the request's tag
presence before calling RememberSizedUntil so anonymous LookupSized(...) calls
cannot hit this entry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2149659e-1da5-4ed2-b2be-51e63bf0f92b
📒 Files selected for processing (7)
internal/jellycompat/batch_loaders.gointernal/jellycompat/handlers_images.gointernal/jellycompat/image_tag_signer.gointernal/jellycompat/images_test.gointernal/jellycompat/mapping.gointernal/jellycompat/mapping_images_test.gointernal/jellycompat/upstream_types.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/jellycompat/image_tag_signer.go
{"subject":"fix(jellycompat): stabilize signed image tags across restarts","body":"- Sign library poster and episode parent series image tags from canonical paths/thumbhashes instead of presigned URLs so tags survive restarts\n- Accept signed canonical tags in the image handler without a session and fall back to legacy URL-derived cache tags\n- Always fetch series detail for episodes to build stable parent image tags"}
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 44f90dd. Configure here.
|
|
||
| if tag = strings.TrimSpace(tag); tag != "" { | ||
| if url, ok := c.lookupTag(tag); ok { | ||
| return url, true |
There was a problem hiding this comment.
LookupSized no longer falls back to route cache on tag miss
Medium Severity
LookupSized previously tried the tag cache first, then fell back to the route cache on a tag miss. Now it returns c.LookupTag(tag) directly, which means a tag-cache miss immediately returns ("", false) without ever consulting the route cache. Any existing caller of Lookup or LookupSized that passes a non-empty tag will lose the route-cache fallback behavior they previously relied on.
Reviewed by Cursor Bugbot for commit 44f90dd. Configure here.
| } | ||
|
|
||
| return catalog.ResolvedImageURL{}, false, nil | ||
| } |
There was a problem hiding this comment.
Signed-tag image path skips access control checks
Medium Severity
resolveItemImageURLFromReposWithoutSession fetches items, episodes, and seasons via their repos and serves images without calling EnsureAccessible. The session-based equivalent (resolveItemImageURLFromRepos) enforces library/rating access controls. A valid signed tag generated for one user can be used by another user who lacks access to that library, bypassing per-user access filtering.
Reviewed by Cursor Bugbot for commit 44f90dd. Configure here.
feat(jellycompat): sign image tags and accept them without session
feat(jellycompat): sign image tags and accept them without session


Summary
/Items/{id}/Images/{type}requests to authorize via a valid signedtagquery param, bypassing session/cache lookups for items, episodes, and seasons.Testing
go test ./internal/jellycompat/...— Not runNote
Medium Risk
Introduces session-less image access gated only by tag verification (plus legacy cache), keyed on the JWT secret—important for client UX but worth reviewing for tag forgery and access boundaries on edge cases.
Overview
Jellyfin-compat image tags move from URL-derived hashes to HMAC-signed tags (keyed on the JWT secret) built from stable seeds: storage paths, thumbhashes, and
updatedAt, so tags stay valid across presign rotation and server restarts./Items/{id}/Images/{type}can now serve artwork when the client passes a matching signedtag, without a session—after verifying the tag against catalog rows (items, episodes, seasons) or library poster paths, with a fallback to legacy URL tags in the image cache. Invalid or stale tags are rejected before route-cache hits.DTO mapping and episode batch loading thread paths/thumbhashes through for tag generation; parent series artwork on episodes uses a
seriesImageSetand episode detail always loads series metadata (no longer skipping that fetch when URLs are cached). Library views exposePosterPathfor stable library primary tags.Reviewed by Cursor Bugbot for commit 44f90dd. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Security