Potential fix for code scanning alert no. 34: Information exposure through an exception#17
Merged
Potential fix for code scanning alert no. 34: Information exposure through an exception#17
Conversation
…rough an exception Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Potential fix for https://github.com/atiilla/GeoIntel/security/code-scanning/34
General approach: Ensure that client-facing responses never include raw exception messages or type names. Instead, log detailed error information on the server and return generic messages. Specifically, adjust
GeoIntel.locateso that on errors it returns a safe, generic error structure withoutstr(e)ortype(e).__name__, and, in the web handler, avoid blindly returning whateverresultcontains on error.Best concrete fix with minimal behavior change:
In
geointel/geointel.py, update the twoexceptblocks inGeoIntel.locate:str(e)andexc_info=True.str(e)or the exception class name. For example:GeoIntelError:"error": "Request cannot be processed"and optionally a generic"details": "GeoIntelError"or omitdetails.Exception:"error": "An unexpected error occurred"and omit or genericizedetails."error"key when something goes wrong, but without internal detail.In
geointel/web_server.py’sanalyze_image:jsonify(result), 400directly when'error' in result, wrap it into a safer structure that does not trust arbitrary contents fromGeoIntel.locate. For example:error_message = result.get("error") or "Request could not be processed"but clamp it to a short, non-technical message.resultentirely and always return a fixed generic 400 for these cases, but that is a slightly larger behavior change.Given the information-exposure focus, the single most impactful change is to sanitize what
GeoIntel.locatereturns, removing inclusion ofstr(e)in returned data, and to avoid echoing any untrusteddetailsto clients.Concretely:
Edit
geointel/geointel.pylines 46–59 to:logger.error(...)calls but adjustreturndicts to:GeoIntelError: nostr(e)or type name in the client-visible dict (or use a non-specific code like"invalid_request").Exception: nostr(e)at all in returned dict.Edit
geointel/web_server.pyaround lines 169–174:'error' in result, construct a new dict with a generic message rather than passing through the entireresult. This also future-proofs against any other sensitive fields that might be added toresultlater.No new utilities or external libraries are required; we only use existing logging and Flask facilities.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.