Skip to content

fix(api): hardening batch — recovery order, request IDs, MIME allowlist#9

Merged
RndmCodeGuy20 merged 1 commit into
stagingfrom
fix/api-hardening
Jun 16, 2026
Merged

fix(api): hardening batch — recovery order, request IDs, MIME allowlist#9
RndmCodeGuy20 merged 1 commit into
stagingfrom
fix/api-hardening

Conversation

@RndmCodeGuy20

Copy link
Copy Markdown
Owner

Closes DEV-36, DEV-37, DEV-38.

Three independent Go API correctness fixes batched into one PR.

DEV-36 — RecoveryMiddleware ordering

Moved RecoveryMiddleware to the outermost app-level position (after RequestID/RealIP, before cors/logger) so panics in any inner middleware are caught and returned as 500 instead of crashing the process. It takes the base logger directly, so it doesn't depend on LoggerMiddleware running first.

DEV-37 — biased fallback request IDs

randomString used time.Now().UnixNano() % len per char → identical chars within a nanosecond, collisions under load. Replaced with math/rand/v2 (concurrency-safe, unbiased). Test asserts charset, length, and 1000-call uniqueness.

DEV-38 — duplicate MIME allowlists

Replaced the handler's private allowedMIMETypes with a single source of truth repository.SupportedMIMETypes (+ IsSupportedMIMEType). The broad ToAssetTypeFromMimeType classifier stays for stored typing. Test pins the gate set.

🤖 Generated with Claude Code

- Move RecoveryMiddleware outermost so panics in inner middleware are caught (DEV-36)
- Replace time-based request-ID chars with math/rand/v2 (unbiased, no collisions) (DEV-37)
- Centralise supported MIME types in repository.SupportedMIMETypes; handler gates against it (DEV-38)
- Add tests for request-ID generation and the MIME gate
@RndmCodeGuy20 RndmCodeGuy20 merged commit 44ed6e8 into staging Jun 16, 2026
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