Skip to content

🔒 [security fix] Fix Unbounded In-Memory Job Storage Leading to Resource Exhaustion - #52

Merged
chottokun merged 1 commit into
mainfrom
fix/unbounded-job-storage-17267331644983903605
Aug 30, 2026
Merged

chottokun merged 1 commit into
mainfrom
fix/unbounded-job-storage-17267331644983903605

Conversation

@chottokun

Copy link
Copy Markdown
Owner

🎯 What: Unbounded In-Memory Job Storage Leading to Resource Exhaustion

⚠️ Risk: The global in-memory job store (jobs) could grow unbounded as background OCR jobs are created. An attacker could exploit this by spawning a large number of asynchronous jobs, causing high memory usage and eventually triggering an Out of Memory (OOM) crash, leading to a Denial of Service (DoS).

🛡️ Solution: Updated the InMemoryJobStore class to be bounded and thread-safe:

  1. Added max_size (default: 1000) and ttl_seconds (default: 3600.0s) parameters, configurable via env variables (JOB_STORE_MAX_SIZE, JOB_STORE_TTL_SECONDS).
  2. Implemented Least Recently Used (LRU) eviction when the job store size reaches the maximum capacity.
  3. Implemented Time-To-Live (TTL) based eviction upon accesses (get/set/exists calls) to purge expired jobs.
  4. Added threading.Lock to ensure job store queries and updates are atomic and thread-safe.
  5. Added unit, integration, and concurrency tests in tests/test_job_store_limits.py verifying all eviction and synchronization behaviors.

PR created automatically by Jules for task 17267331644983903605 started by @chottokun

…o prevent resource exhaustion

* Created bounded InMemoryJobStore implementing Least Recently Used (LRU) eviction.
* Added Time-To-Live (TTL) eviction policy for old jobs.
* Implemented threading.Lock for full thread safety of job store operations.
* Exposed maximum size and TTL via environment variables with secure defaults.
* Added unit/integration tests to verify eviction policies, TTL, and thread safety.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chottokun
chottokun merged commit 994cc1b into main Aug 30, 2026
1 check passed
@chottokun
chottokun deleted the fix/unbounded-job-storage-17267331644983903605 branch August 30, 2026 13:05
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