Fix information disclosure via unhandled exceptions in GetGodAsync#7
Draft
Fix information disclosure via unhandled exceptions in GetGodAsync#7
Conversation
Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unhandled exceptions in GetGodAsync method
Fix information disclosure via unhandled exceptions in GetGodAsync
Feb 19, 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.
GetGodAsyncusedFirstAsync(), throwingInvalidOperationExceptionfor non-existent IDs. In development mode, this exposed stack traces with database schema, file paths, and framework versions (CWE-209).Changes
Repository Layer
FirstAsync()→FirstOrDefaultAsync()with nullableTask<God?>return type.Include(g => g.Aliases)for proper entity loadingEndpoint Layer
400 Bad Requestforid <= 0404 Not Foundwith structured JSON error messagesGlobal Exception Handler
ExceptionHandlingMiddlewareto catch unhandled exceptionsExample
Response changes:
GET /api/v1/gods/99999:500with stack trace →404with{"error": "God with ID 99999 not found"}GET /api/v1/gods/-1:500with stack trace →400with{"error": "ID must be a positive integer"}Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
105.130.85.20.in-addr.arpa/usr/bin/lsof lsof -i -P(dns block)24.113.82.140.in-addr.arpa/usr/bin/lsof lsof -i -P(dns block)34.11.16.104.in-addr.arpa/usr/bin/lsof lsof -i -P(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>🔴 CRITICAL: Unhandled Exceptions Expose System Information</issue_title>
<issue_description>## Description
The
GetGodAsyncmethod inGodRepository.cs(line 63) usesFirstAsync()without null checking, causing unhandled exceptions that expose sensitive system information to clients. Additionally, the application lacks global exception handling middleware.Vulnerable Code:
When a non-existent ID is requested via
GET /api/v1/gods/{id}, this throws anInvalidOperationExceptionthat bubbles up unhandled. In development mode, this returns a 500 error with a full stack trace exposing:Security Implications
Example
Solution
Implement proper exception handling at both the repository and middleware levels.
Step 1: Fix Repository Method
File:
src/Gods/DBRepositories/GodRepository.cs(lines 63-66)Update Interface:
src/Gods/Interfaces/IGodRepository.csStep 2: Handle Null in Endpoint
File:
src/Endpoints/v1/Gods.cs(line 16)Step 3: Add Global Exception Handler Middleware
Create:
src/Common/Middleware/ExceptionHandlingMiddleware.cs