Sanitize error responses to prevent internal detail leakage#70
Merged
Conversation
2e5a25f to
30f98ab
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
4354507 to
8ccbb10
Compare
Replace all raw str(e) exception messages in API responses with safe_error_message() that maps known exception types to generic messages and logs the real error server-side. Also sanitize Pydantic validation errors in views.py to strip input, ctx, and url fields.
8ccbb10 to
f7ff7c6
Compare
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
safe_error_message()utility that maps known Django exception types (IntegrityError, FieldError, OperationalError, ValidationError, ValueError, TypeError) to generic client-safe messages while logging the real exception server-sidestr(e)in handler error responses acrosscrud.py,actions.py,relations.py, andmeta.pysanitize_pydantic_errors()to stripinput,ctx, andurlfields from Pydantic validation errors inviews.pyWhat could leak before this fix
IntegrityError→ table/column names, constraint namesFieldError→ valid field names and model schemaOperationalError→ database host/connection infoFileNotFoundError→ internal file pathse.errors()→ internal field types, input values, contextTest plan
safe_error_messagemaps each exception type to its generic messagelogger.exception()sanitize_pydantic_errorsstripsinput,ctx,urlfieldsstr(e)or unsanitizede.errors()remain in source