fix(web): return 400 (not 500) for missing required tenant header (#1245)#1247
Merged
Conversation
fix(web): return 400 (not 500) for malformed requests / missing required params Anonymous, tenant-scoped endpoints (forgot-password, reset-password, self-register) bind a required `tenant` header. When it is missing, ASP.NET Core throws BadHttpRequestException (StatusCode 400) during parameter binding. GlobalExceptionHandler did not recognise that type and rendered it as a generic 500. Map BadHttpRequestException to its own StatusCode so missing required header/route/query params (and unreadable/oversized bodies) surface as a proper 400 (or 413, etc.) with a ProblemDetails body. The fix applies to every endpoint with a required bound parameter, not just identity. Mirror the mapping in the test-only DetailedTestExceptionHandler, add integration regression tests for the three identity endpoints, and add GlobalExceptionHandler unit tests. Closes #1245 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> @
This was referenced May 26, 2026
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
Fixes #1245 — a tenant-scoped endpoint returned 500 Internal Server Error when the tenant ID was missing, instead of a proper client error.
Root cause
The anonymous, tenant-scoped identity endpoints (
forgot-password,reset-password,self-register) bind a required[FromHeader] tenantparameter. When it is missing, ASP.NET Core throwsMicrosoft.AspNetCore.Http.BadHttpRequestException(which carriesStatusCode = 400) during parameter binding.GlobalExceptionHandlerdid not recognise that type, so it fell through to the generic 500 branch.Notes from the investigation:
tenantclaim resolves the tenant even without the header, so the bug only bites the anonymous endpoints that require the header.Fix
GlobalExceptionHandlernow mapsBadHttpRequestExceptionto its ownStatusCode(400, or 413 for oversized bodies, etc.) with aProblemDetailsbody. This covers every endpoint with a required bound header/route/query param, not just identity.DetailedTestExceptionHandlerso tests reflect production behaviour.Tests
forgot-password/reset-password/self-registerwithout thetenantheader now return 400 (were 500).GlobalExceptionHandlerunit tests (400, 413,CustomExceptionpass-through, 500 default).Docs
Changelog entry: fullstackhero/docs#218
🤖 Generated with Claude Code