Reject album share tokens in media queries without a panic
Author: coderabbitai[bot]Created Sep 21, 2026Updated Sep 24, 2026
Labelsbughelp wantedgood first issueAPIhigh prioritygosecurity
Summary
queryResolver.Media dereferences shareToken.MediaID without first checking whether it is nil.
Album share tokens have no media ID. If a caller supplies album-token credentials to the media query, the resolver can dereference a nil pointer.
Security and reliability impact
The failure can cause a panic. The GraphQL recovery configuration determines whether the effect is limited to one request or affects the process. The resolver must reject credentials that do not apply to the requested resource type before it dereferences token-specific fields.
Affected area
api/graphql/resolvers/media.goqueryResolver.Media- Share-token credential validation for media queries
Required changes
- Validate the share-token type before accessing
shareToken.MediaID. - Reject album-token credentials for
mediawith a controlled authorization or validation error. - Preserve valid media-token access behavior.
- Add regression tests for the token-type mismatch.
Implementation plan
- Trace how
queryResolver.Mediaparses and validates share-token credentials. - Add a nil check or explicit token-type check before dereferencing
shareToken.MediaID. - Return the established GraphQL authorization or validation error for an album token supplied to
media. - Confirm that valid media-token credentials still grant access only to the token's media item.
- Add resolver tests for album-token credentials, media-token credentials, missing credentials, and mismatched media IDs.
- Confirm that the mismatch path returns an error and does not panic.
Acceptance criteria
- Supplying album-token credentials to
queryResolver.Mediareturns a controlled error. - The resolver does not dereference a nil
shareToken.MediaID. - Valid media-token credentials continue to work for their linked media item.
- Automated tests cover the album-token and media-query mismatch.
- The test suite verifies that this path does not panic.
Backlinks
- Reported during security review of https://github.com/photoview/photoview/pull/1495.
- Original review comment: https://github.com/photoview/photoview/pull/1495#discussion_r4035242542.
- Requested by @kkovaletp.
Source: photoview/photoview