Skip to content

fix(security): remediate token logging, doc decompression limits, and storage/auth concurrency - #17

Merged
souravC01 merged 4 commits into
mainfrom
fix/security-and-concurrency-remediation
Sep 14, 2026
Merged

souravC01 merged 4 commits into
mainfrom
fix/security-and-concurrency-remediation

Conversation

@souravC01

Copy link
Copy Markdown
Owner

Summary

Remediates four security and concurrency vulnerabilities covering token leakage in server logs, decompression safety in Word .doc file parsing, atomic storage quota reservation across concurrent uploads, and atomic single-transaction password reset token consumption.


Key Changes

  1. Eliminate Sensitive Token Logging (backend/routers/auth.py, tests/test_auth_api.py):

    • Removed unconditional print() statements outputting raw email verification and password reset recovery links with usable tokens.
    • Replaced with sanitized operational log messages that exclude tokens and URLs.
    • Removed user account existence leak on invalid password reset requests.
    • Added automated test (test_tokens_not_printed_to_logs) capturing stdout/stderr to ensure no token leakage.
  2. Enforce Decompression Safety Limit on Word .doc Files (backend/services/document_parser.py, tests/test_document_parser.py):

    • Unified decompression bomb safety verification so any zip-based archive (whether named .docx or .doc) is verified against the 50 MB uncompressed limit before invoking docx.Document.
    • Maintained friendly rejection for legacy non-zip binary Word files ("Legacy .doc binary format is not supported...").
    • Added tests ensuring renamed zip bombs are blocked, valid OOXML .doc files parse, and legacy binary .doc files are rejected.
  3. Enforce Atomic Storage Quota Reservations (backend/storage.py, backend/services/resume_files.py, tests/test_atomic_limits.py):

    • Added reserve_upload_bytes and finalize_attachment methods to StorageService using transactional locking.
    • Included both active and reserved attachments in get_user_upload_bytes calculation.
    • Reserved storage quota atomically in the database before dispatching to object storage, releasing reservations to failed state on network or insertion failure.
    • Added automated concurrency test (test_concurrent_uploads_cannot_exceed_storage_quota) verifying simultaneous uploads obey exact storage quotas.
  4. Atomic Password Reset & Verification Token Consumption (backend/storage.py, backend/routers/auth.py, tests/test_atomic_limits.py):

    • Added consume_reset_token_and_update_password to atomically validate the token, check expiration, consume it (used_at IS NULL), invalidate other prior tokens, and update the password and session version in a single transaction.
    • Added single-transaction verification consumption (consume_verify_token_and_verify_user) and hardened consume_auth_token to return rowcount boolean.
    • Added automated concurrency test (test_concurrent_password_reset_confirm_only_succeeds_once) confirming racing confirmation requests can only consume a token once.

Verification & Test Results

  • Backend Pytest (pytest):
    • 211/211 passed in 36.96s (100% passing across all unit and concurrency suites).
  • Frontend Vitest (npm test -- --run):
    • 47/47 passed across 13 test files.
  • Frontend Build (npm run build):
    • Production build completed cleanly in 1.93s.
  • Git Check (git diff --check):
    • Clean diff with zero whitespace or syntax issues.

…word recovery

Remove raw token and recovery URL printing from stdout/stderr during registration and password reset workflows. Add automated test coverage confirming plaintext tokens are not leaked to server logs.
Apply the 50 MB uncompressed zip safety guard to both .docx and .doc archives before parsing with python-docx, preventing decompression bomb expansion in renamed OOXML documents. Reject non-zip legacy binary files with an informative error.
…t uploads

Reserve account storage bytes atomically in database before uploading to object storage, releasing reservations on failure. Count reserved and active attachments towards storage limit to prevent concurrent uploads from exceeding quota.
Validate, consume (used_at IS NULL), and apply password changes in a single database transaction, preventing concurrent recovery requests from overwriting passwords multiple times. Add single-transaction email verification consumption and automated concurrency test coverage.
@vercel

vercel Bot commented Sep 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
jobhelperguru Ready Ready Preview Sep 14, 2026 3:02am UTC

@souravC01
souravC01 merged commit 4313a91 into main Sep 14, 2026
14 checks passed

This branch was successfully deployed

1 active deployment
Preview — 44d4c510 Deployed Sep 14, 2026 by vercel[bot]
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