Skip to content

fix(student-card): protect cached data and enforce validity dates - #388

Merged
jakobkoerber merged 3 commits into
mainfrom
fix/student-card-security
Nov 14, 2026
Merged

jakobkoerber merged 3 commits into
mainfrom
fix/student-card-security

Conversation

@jakobkoerber

Copy link
Copy Markdown
Member

Issue

No linked issue. Cached cards could keep displaying an unconditional VALID badge after their validity dates passed. The cache also persisted token-bearing URLs and plaintext card details, and requests completing after logout could repopulate it.

Why this is useful for all students

Protects stored student-card photos and personal details, keeps expired cards visibly expired while offline, and prevents signed-out sessions from restoring old data.

Changes

  • Encrypt student-card response bodies with AES-256-GCM and keep the key in secure storage. Bind ciphertext to the account-specific cache key; treat missing keys, legacy plaintext and failed authentication as cache misses.
  • Hash authenticated cache URLs instead of persisting bearer tokens. Move disposable data to the application cache directory, clear the legacy Documents cache, and add a primary key so refreshes replace existing entries.
  • Invalidate in-flight REST responses when clearing the cache, serialize cleanup with pending writes, destroy the card key on reset, clear the in-memory token at logout start, and ignore updates to disposed card models.
  • Preserve the original animated VALID badge only within the card's validity dates. Show expired, not-yet-valid or invalid-date states and recheck while open and on resume. No cached/retrieved-data notice is shown.
  • Add a debug-only synthetic preview for all four validity states.

Screenshot

The synthetic expired-card preview was visually checked in the iOS simulator. Reproduce with:

flutter run -t lib/dev/student_card_preview.dart

Validation

  • Complete Flutter suite: 460 tests passed.
  • flutter analyze --no-pub: no issues.
  • Formatting and git diff --check: passed.
  • Coverage includes encrypted persistence, tampering, account substitution, missing keys, cache replacement, pending writes and late responses after logout, and expiry before the 30-day cache window ends.

Scope and migration

The upgrade discards existing cache entries; offline data becomes available again after a successful fetch. The cache directory may also be purged by the operating system.

These frontend changes protect local data and validity handling; they do not establish independent authenticity for a displayed card or detect early revocation while offline. Backend verification and production token transport changes are outside this PR.

@jakobkoerber
jakobkoerber marked this pull request as ready for review November 14, 2026 14:07
@jakobkoerber
jakobkoerber merged commit 20992cd into main Nov 14, 2026
3 checks passed
@jakobkoerber
jakobkoerber deleted the fix/student-card-security branch November 14, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant