Skip to content

feat(security): hash API keys, lock down audit logs, enforce route ownership - #397

Open
MatanOga01 wants to merge 1 commit into
UnityChainxx:mainfrom
MatanOga01:fix/matanoga01-security-hardening
Open

feat(security): hash API keys, lock down audit logs, enforce route ownership#397
MatanOga01 wants to merge 1 commit into
UnityChainxx:mainfrom
MatanOga01:fix/matanoga01-security-hardening

Conversation

@MatanOga01

Copy link
Copy Markdown

Resolves the Stellar Wave issues assigned to MatanOga01.

Changes

API key hashing and rotation (#252)

  • Raw API keys are never persisted: only a SHA-256 hash plus a 4-char display hint is stored.
  • The raw secret is returned exactly once, at creation/rotation time.
  • New POST /api-keys/rotate/:key endpoint; revocation and expiry still enforced.
  • Verification uses constant-time comparison; endpoint scope enforcement (incl. wildcards) with tests.

Audit-log tamper and access controls (#249)

  • All audit-log routes are restricted to admins (JwtAuthGuard + RolesGuard), so ordinary users cannot read or modify records.
  • Logs remain append-only; no public update/delete mutations exist.
  • New admin-only GET /admin/audit-logs/export (CSV) and DELETE /admin/audit-logs/older-than/:days (retention purge) endpoints.

Authorization on user-ID routes (#266)

  • New @Ownership() decorator + global OwnershipGuard enforce that callers can only access their own data, unless they carry an explicit admin role.
  • Applied across analytic history, progress, streaks, rewards, reactions, report cards, rankings, time trials, multiplayer queue, puzzle dependency and reward-shop routes that take a userId.

Contract storage versioning (#269)

  • New onchain/docs/storage-versioning.md defining the migration strategy for storage keys and serialized types.
  • Compatibility tests: schema version before init, legacy Question readability, LevelProgress round-trip, and stable Levels discriminants.

Tests

  • 61 backend unit tests pass (api-key, audit-log, ownership guard).

Closes #249
Closes #252
Closes #266
Closes #269

…nership

- API keys: persist only SHA-256 hashes, return the raw secret once at
  creation, support rotation/revocation, constant-time verification and
  endpoint scope enforcement (UnityChainxx#252)
- Audit logs: admin-only reads and CSV export, retention purge, no public
  mutation paths (UnityChainxx#249)
- Ownership guard on user-ID routes: callers may only access their own
  data unless they hold an explicit admin role (UnityChainxx#266)
- Onchain: document storage versioning/migration strategy and add
  compatibility tests for legacy state (UnityChainxx#269)

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@MatanOga01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant