#1501·photoview

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.go
  • queryResolver.Media
  • Share-token credential validation for media queries

Required changes

  1. Validate the share-token type before accessing shareToken.MediaID.
  2. Reject album-token credentials for media with a controlled authorization or validation error.
  3. Preserve valid media-token access behavior.
  4. Add regression tests for the token-type mismatch.

Implementation plan

  1. Trace how queryResolver.Media parses and validates share-token credentials.
  2. Add a nil check or explicit token-type check before dereferencing shareToken.MediaID.
  3. Return the established GraphQL authorization or validation error for an album token supplied to media.
  4. Confirm that valid media-token credentials still grant access only to the token's media item.
  5. Add resolver tests for album-token credentials, media-token credentials, missing credentials, and mismatched media IDs.
  6. Confirm that the mismatch path returns an error and does not panic.

Acceptance criteria

  • Supplying album-token credentials to queryResolver.Media returns 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