security: API key rotation grace period, encryption at rest, CSP headers, SQL injection prevention - #783
Merged
Smartdevs17 merged 1 commit intoAug 28, 2026
Conversation
- rotate API keys with a grace period instead of immediate revocation, and surface grace-period/rotation status in usage tracking - add customer-managed KMS key and wire it into RDS, secrets manager, and backup vault encryption at rest - apply the existing CSP middleware/headers to the backend and frontend - parameterize the SQL helper and validate dynamic SQL identifiers used by the timescale repository
|
@hardcordev 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! 🚀 |
|
@hardcordev is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens the API against four security gaps: immediate (no grace-period) API key rotation, database/secrets encryption relying on AWS default-managed keys instead of a dedicated key, CSP headers that were written but never applied, and a "safe" SQL query helper plus a raw-SQL repository that both allowed unescaped values/identifiers into query strings.
Changes
backend/src/services/keys/rotation.tswithrotateApiKeyWithGracePeriod(keeps the predecessor key active until a configurable grace-period deadline while issuing a new key) andsettleGracePeriod(lazy expiry once the deadline passes). Wired intobackend/src/routes/api-keys.ts's/rotate, list, get, and usage endpoints, which now also report rotation/grace-period status. AddedrotatedAt,gracePeriodEndsAt,predecessorKeyId,successorKeyIdcolumns to theApiKeymodel plus a matching migration.infra/main.tf) and wired it into RDS storage encryption, RDS Performance Insights, both Secrets Manager secrets, and the AWS Backup vault, replacing reliance on AWS default-managed keys.contentSecurityPolicy()middleware inbackend/src/index.ts, and added the equivalent CSP plus supporting security headers (X-Content-Type-Options,X-Frame-Options,Referrer-Policy,Permissions-Policy) tofrontend/next.config.ts.SQLInjectionPrevention.createSafeQueryinbackend/src/middleware/security.tsno longer interpolates escaped values into the query string — it now returns genuinely parameterized$nplaceholders for the caller to bind.TimescaleRepository.ts's dynamic table/column identifiers (which can't be parameterized) are now validated against a strict allowlist before being interpolated.Issues
Resolves #756
Resolves #754
Resolves #751
Resolves #750
Verification
Manual code review completed for every change (git status / diff / full diff reviewed file-by-file).
cargo buildandcargo testwere not run — verification was manual review only, per repository guidance. No snapshots were added or modified.