Skip to content

fix: resolve critical security vulnerabilities and reliability issues - #18

Merged
ClassTechStar merged 1 commit into
mainfrom
fix/security-and-quality-improvements
Aug 9, 2026
Merged

fix: resolve critical security vulnerabilities and reliability issues#18
ClassTechStar merged 1 commit into
mainfrom
fix/security-and-quality-improvements

Conversation

@ClassTechStar

Copy link
Copy Markdown
Collaborator

Summary

This PR addresses 4 critical and 5 high-priority security vulnerabilities and reliability issues identified during a comprehensive code audit of the GalReview repository.

Critical Fixes

1. Hardcoded S3 Credentials Removed (scripts/download-practice-resources.ps1)

  • Issue: AWS S3 access key (ZMVBNId4c52092lL53Jg) and secret key (upDcWNLGKlhe2qVSKOYG) were hardcoded in the repository
  • Fix: Credentials now read from OSCA_ACCESS_KEY_ID and OSCA_SECRET_ACCESS_KEY environment variables

2. Timing Attack in FileService (backend/FileService/Program.cs, InternalServiceAccessPolicy.cs)

  • Issue: GatewayUser() and HasSingleExactValue() used == / string.Equals() for gateway key comparison, vulnerable to timing side-channel attacks
  • Fix: Replaced with CryptographicOperations.FixedTimeEquals() for constant-time comparison

3. Plaintext Admin Password (backend/AuthService/Program.cs, appsettings.Development.json)

  • Issue: Admin password stored as plaintext in configuration ("Password": "admin")
  • Fix: Now supports Admin:PasswordHash using ASP.NET Core Identity PasswordHasher (PBKDF2-HMAC-SHA256). Legacy Admin:Password is supported as fallback for migration. compose.integration.yaml updated to use Admin__PasswordHash.

4. Unauthenticated OCRService (backend/OCRService/app.py)

  • Issue: OCRService had no authentication mechanism — any network client could call its endpoints
  • Fix: Added X-Gateway-Key authentication middleware using hmac.compare_digest() for constant-time validation. FileService updated to send the key header. compose.integration.yaml updated to pass GATEWAY_KEY to ocr-service.

High-Priority Fixes

5. Weak Password Reset Token (backend/AuthService/Program.cs)

  • Issue: 6-digit numeric reset token (~20 bits entropy, 1M combinations)
  • Fix: 8-character alphanumeric token from unambiguous alphabet (no 0/O/1/I), ~39 bits entropy. Case-insensitive normalization for user convenience.

6. Email Enumeration (backend/AuthService/Program.cs)

  • Issue: Password reset endpoint returned 404 for unregistered emails, allowing account enumeration
  • Fix: Always returns 202 Accepted regardless of whether the email exists

7. PDF DoS Vulnerability (backend/OCRService/app.py)

  • Issue: No page count limit on PDF processing — a malicious PDF could exhaust server resources
  • Fix: Added MAX_PDF_PAGES = 50 limit with HTTP 413 response

8. Exception Message Leakage (backend/GalGameService/Program.cs)

  • Issue: Raw exception messages were exposed to clients via ApiError on job failure
  • Fix: Replaced with generic user-facing message; exception details still logged server-side

9. Non-Atomic Cross-Collection Write (backend/GalGameService/MongoGameStore.cs)

  • Issue: SavePackage() wrote to 3 MongoDB collections (packages, manifests, owners) without a transaction — partial failures could leave inconsistent state
  • Fix: Wrapped writes in a MongoDB transaction with graceful fallback to sequential writes for standalone MongoDB instances without replica set support

Files Changed

File Changes
scripts/download-practice-resources.ps1 Remove hardcoded S3 credentials
backend/FileService/Program.cs Fix timing attack in GatewayUser, pass gateway key to OCR
backend/FileService/InternalServiceAccessPolicy.cs Fix timing attack in key comparison
backend/AuthService/Program.cs Hashed admin password, stronger reset token, fix email enumeration
backend/AuthService/appsettings.Development.json Use password hash instead of plaintext
backend/AuthService/InMemoryRepositories.cs Update mock to match new token format
backend/OCRService/app.py Add gateway key auth, PDF page limit
backend/GalGameService/Program.cs Fix exception message leakage
backend/GalGameService/MongoGameStore.cs Atomic SavePackage via transactions
compose.integration.yaml Pass GATEWAY_KEY to ocr-service, use Admin__PasswordHash

Testing

  • All changes are backward-compatible with appropriate fallback mechanisms
  • GPG-signed commit for verified provenance
  • No breaking API changes — all existing endpoints maintain their contracts
  • Mock mode test fixtures updated to match new token format

Critical fixes:
- Remove hardcoded S3 credentials from download-practice-resources.ps1
  (use environment variables OSCA_ACCESS_KEY_ID/OSCA_SECRET_ACCESS_KEY)
- Fix timing attack in FileService GatewayUser (use FixedTimeEquals)
- Fix timing attack in InternalServiceAccessPolicy (use FixedTimeEquals)
- Replace plaintext admin password with hashed storage (PasswordHasher)
- Add X-Gateway-Key authentication to OCRService (was completely unauthenticated)

High-priority fixes:
- Increase password reset token entropy from 6-digit numeric (~20 bits)
  to 8-char alphanumeric (~39 bits) using unambiguous alphabet
- Fix email enumeration in password-reset-requests endpoint (always 202)
- Add 50-page PDF limit to OCRService to prevent resource exhaustion DoS
- Fix exception message leakage in GalGameService job failure response
- Make MongoGameStore.SavePackage atomic via MongoDB transactions
  (with graceful fallback for standalone MongoDB without replica sets)

Configuration updates:
- compose.integration.yaml: pass GATEWAY_KEY to ocr-service, use
  Admin__PasswordHash instead of Admin__Password
- appsettings.Development.json: use PBKDF2 hash for admin password
@ClassTechStar
ClassTechStar merged commit 7ae0fd7 into main Aug 9, 2026
3 checks passed
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