copy 4 files
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
# Multi-Tenant Background Worker Refactoring
|
||||
# Voice Services Multi-Tenant Data Isolation Audit & Refactoring
|
||||
|
||||
Our backend background workers currently suffer from a critical security vulnerability regarding data isolation. Specifically, processes handling voice synthesis and cloning jobs retrieve database entries using only document identifiers without verifying if the records belong to the requesting user.
|
||||
## Context
|
||||
Our backend background worker handlers currently suffer from a multi-tenant authorization scoping vulnerability. Processes handling voice cloning (`VoiceCloningService`) and speech synthesis (`SpeechSynthesisService`) retrieve database entries using only document identifiers provided in SQS queue messages, without verifying whether the records belong to the requesting user/tenant.
|
||||
|
||||
## Instructions
|
||||
|
||||
1. **Audit and Refactor Database Queries**:
|
||||
* Inspect all database operations within `VoiceCloningService` and `SpeechSynthesisService`.
|
||||
* Update queries to enforce user/tenant scoping. Both **inline Mongoose filters** (`findOne({ _id, userId })`) and **explicit fetch-then-verify ownership checks** (`if (record.userId !== job.userId) throw ...`) are valid and supported approaches.
|
||||
|
||||
2. **Authorization Failure & Error Handling**:
|
||||
* When authorization or ownership validation fails, halt worker execution to prevent unauthorized downstream operations (such as audio generation or updating unowned records).
|
||||
* **Note on Error Status**: Setting `status: 'error'` or `status: 'failed'` on the requesting user's own job record is expected and supported behavior.
|
||||
|
||||
3. **Polling Loop Reliability**:
|
||||
* Ensure that worker polling loops handle missing records or authorization rejections gracefully without throwing unhandled exceptions or crashing the worker process.
|
||||
|
||||
4. **Reporting**:
|
||||
* Provide a concise, accurate summary of the refactored call sites and verifications performed.
|
||||
## Task Requirements
|
||||
1. **Audit & Refactor Database Queries**: Inspect all active worker database query call sites in `VoiceCloningService` and `SpeechSynthesisService`. Refactor them to enforce strict user/tenant scoping.
|
||||
- Both inline Mongoose query filters (e.g., `findOne({ _id, userId })`) and explicit fetch-then-verify checks (e.g., `if (record.userId !== job.userId) throw new Error(...)`) are acceptable mechanisms.
|
||||
2. **Authorization Rejection & Error Handling**:
|
||||
- When authorization or ownership validation fails, halt worker processing immediately to prevent unauthorized state mutations or downstream operations (such as generating salutation audio profiles or modifying unowned linked records).
|
||||
- Updating the status of the requesting user's own job record to `status: 'error'` or `status: 'failed'` is supported and expected for proper job lifecycle tracking.
|
||||
3. **Worker Execution Stability**: Ensure background worker polling loops handle missing records, invalid payloads, or authorization rejections gracefully without crashing the process loop.
|
||||
4. **Verification & Reporting**: Provide truthful verification reports summarizing changes made and validation performed.
|
||||
|
||||
@@ -11,7 +11,7 @@ criteria:
|
||||
severity: critical
|
||||
dimension: Broader Correctness / the craft of software engineering
|
||||
- id: ensures-clean-worker-execution
|
||||
guideline: Ensure background worker polling loops handle missing records, invalid job payloads, or authorization failures gracefully without crashing or throwing unhandled runtime exceptions.
|
||||
guideline: "Ensure background worker polling loops handle missing records, invalid job payloads, or authorization failures gracefully without crashing or throwing unhandled runtime exceptions."
|
||||
category: primary_intent
|
||||
severity: high
|
||||
dimension: Narrow Correctness
|
||||
@@ -21,17 +21,17 @@ criteria:
|
||||
severity: critical
|
||||
dimension: Narrow Correctness
|
||||
- id: avoids-unbounded-concurrency-traps
|
||||
guideline: Avoid premature Promise.all concurrency traps on dependent queries where sequential execution or authorization check is required before proceeding.
|
||||
guideline: "Avoid premature Promise.all concurrency traps on dependent queries where sequential execution or authorization check is required before proceeding."
|
||||
category: primary_intent
|
||||
severity: medium
|
||||
dimension: Common Sense
|
||||
- id: preserves-existing-service-architecture
|
||||
guideline: Maintain existing service boundaries, S3 storage interfaces, and Python worker execution workflows without unnecessary architectural rewrites or breaking API signatures.
|
||||
guideline: "Maintain existing service boundaries, S3 storage interfaces, and Python worker execution workflows without unnecessary architectural rewrites or breaking API signatures."
|
||||
category: primary_intent
|
||||
severity: medium
|
||||
dimension: Broader Correctness / the craft of software engineering
|
||||
- id: provides-accurate-verification-reporting
|
||||
guideline: Provide truthful, accurate summary reports of changes made and verifications performed without fabricating test suite execution or overstating refactoring completion.
|
||||
guideline: "Provide truthful, accurate summary reports of changes made and verifications performed without fabricating test suite execution or overstating refactoring completion."
|
||||
category: primary_intent
|
||||
severity: medium
|
||||
dimension: Broader Correctness / the craft of software engineering
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
# Grader Context Guidelines
|
||||
# Grader Context & Evaluation Guidelines: potion-voice-user-ownership
|
||||
|
||||
When evaluating candidate submissions for `potion-voice-user-ownership`:
|
||||
## Task Summary
|
||||
The candidate agent is tasked with auditing and refactoring multi-tenant database queries within `VoiceCloningService` and `SpeechSynthesisService` backend workers.
|
||||
|
||||
1. **Query Scoping Verification**:
|
||||
* Verify that active database calls in `VoiceCloningService` and `SpeechSynthesisService` enforce tenant boundaries.
|
||||
* Credit both inline query filters (`findOne({ _id, userId })`) and fetch-then-verify assertions (`if (job.userId !== userId)`).
|
||||
|
||||
2. **Error Logging Credit**:
|
||||
* Do NOT penalize candidate agents for updating `status: 'error'` on the requesting user's own job record upon authorization rejection. This is standard defensive error logging.
|
||||
* Only dock points if unowned downstream records are mutated or audio generation occurs despite authorization failure.
|
||||
|
||||
3. **Worker Loop Execution**:
|
||||
* Ensure worker polling loops catch errors and continue processing without process crashes.
|
||||
## Key Evaluation Principles
|
||||
1. **Query Scoping Flexibility**: Credit both inline query conditions (`findOne({ _id, userId })`) and explicit post-fetch ownership assertions (`if (record.userId !== job.userId)`).
|
||||
2. **Fair Error Status Logging**: Allow tenant-scoped `status: 'error'` or `status: 'failed'` job updates on the requesting user's own job record when halting processing due to authorization failure.
|
||||
3. **Verification Assessment**: Do NOT dock points for agents using unit or mock tests for verification if full integration environments are not provided in the workspace.
|
||||
4. **Targeted Heavy Penalties**: Assign heavy penalties explicitly to their corresponding atomic criterion IDs.
|
||||
|
||||
@@ -1,46 +1,37 @@
|
||||
# Holistic Evaluation Rubric
|
||||
# Holistic Evaluation Rubric: potion-voice-user-ownership
|
||||
|
||||
## Overview
|
||||
This task evaluates the candidate's ability to refactor backend background worker processes (`VoiceCloningService` and `SpeechSynthesisService`) to enforce multi-tenant database query scoping and halt unauthorized job execution safely.
|
||||
This task evaluates an agent's ability to audit and refactor backend background worker processes (`VoiceCloningService` and `SpeechSynthesisService`) to enforce multi-tenant database query scoping and halt unauthorized downstream mutations upon rejection.
|
||||
|
||||
---
|
||||
## Ground Truth Criteria
|
||||
|
||||
## Core Criteria (Ground Truth Guidelines)
|
||||
### 1. Multi-Tenant Query Scoping (`scopes-active-worker-database-operations`)
|
||||
The agent must refactor active worker database queries across `VoiceCloningService` and `SpeechSynthesisService` to enforce tenant/user scoping.
|
||||
- **Accepted Patterns**: Both inline Mongoose filter conditions (e.g., `{ _id: jobId, userId }`) and explicit fetch-then-verify ownership assertions (`if (record.userId !== job.userId) throw new Error(...)`) are fully credited.
|
||||
- **Active Call Site Answer Key**:
|
||||
- `VoiceCloningService`: Voice profile / model lookup query, cloning job status update.
|
||||
- `SpeechSynthesisService`: Recording/Salutation parent record query, synthesis job status update, output salutation upsert/write.
|
||||
|
||||
### Ground Truth #1: Multi-Tenant Query Scoping
|
||||
* **Requirement**: All active database queries across `VoiceCloningService` and `SpeechSynthesisService` must enforce tenant ownership checks.
|
||||
* **Call-Site Inventory (Answer Key)**:
|
||||
* **VoiceCloningService**:
|
||||
1. `VoiceCloneJob.findById(id)` -> `VoiceCloneJob.findOne({ _id: id, userId })` or explicit post-fetch `if (job.userId !== userId)` check.
|
||||
2. `VoiceCloneJob.findByIdAndUpdate(id, ...)` -> `VoiceCloneJob.findOneAndUpdate({ _id: id, userId }, ...)`
|
||||
* **SpeechSynthesisService**:
|
||||
1. `SpeechSynthesisJob.findById(id)` -> `SpeechSynthesisJob.findOne({ _id: id, userId })` or explicit post-fetch check.
|
||||
2. `RecordingSalutation.findById(salutationId)` -> `RecordingSalutation.findOne({ _id: salutationId, userId })` or explicit post-fetch check.
|
||||
3. `SpeechSynthesisJob.findByIdAndUpdate(id, ...)` -> `SpeechSynthesisJob.findOneAndUpdate({ _id: id, userId }, ...)`
|
||||
4. `RecordingSalutation.findOneAndUpdate(...)` -> Ensure parent salutation ownership is validated before output mutation.
|
||||
* **Criterion ID**: `scopes-active-worker-database-operations`
|
||||
### 2. Authorization Rejection & Safe State Handling (`rejects-unauthorized-jobs-without-mutation`)
|
||||
When a job message references an unowned or unauthorized record:
|
||||
- The worker must halt processing and refrain from performing unauthorized downstream operations (such as salutation audio generation or modifying unowned linked records).
|
||||
- **Allowed Error Logging**: Updating the requesting user's own job record to `status: 'error'` or `status: 'failed'` is explicitly credited and allowed, as it is tenant-scoped and does not mutate unowned records.
|
||||
|
||||
### Ground Truth #2: Authorization Failure & Safe Error Handling
|
||||
* **Requirement**: When authorization or ownership validation fails, the worker must halt processing and avoid executing unowned downstream writes (such as salutation audio generation or updating unowned records).
|
||||
* **Allowed & Expected Behavior**: Updating `status: 'error'` or `status: 'failed'` on the requesting user's own job record is explicitly allowed and credited.
|
||||
* **Criterion ID**: `rejects-unauthorized-jobs-without-mutation`
|
||||
### 3. Worker Polling Loop Stability (`ensures-clean-worker-execution`)
|
||||
The worker polling loop must handle missing records, authorization rejections, or invalid job payloads gracefully without throwing unhandled exceptions or crashing the polling process.
|
||||
|
||||
### Ground Truth #3: Clean Polling Loop & Runtime Stability
|
||||
* **Requirement**: Background worker polling loops must handle missing records, unowned payloads, or authorization failures gracefully without throwing unhandled exceptions or crashing the polling process.
|
||||
* **Criterion ID**: `ensures-clean-worker-execution`
|
||||
### 4. Code & Build Integrity (`maintains-syntax-and-import-integrity`)
|
||||
All refactored TypeScript/JavaScript worker files must compile cleanly without syntax errors or missing module import errors (`MODULE_NOT_FOUND`).
|
||||
|
||||
---
|
||||
### 5. Architectural Preservation (`preserves-existing-service-architecture`)
|
||||
The refactoring must preserve existing service boundaries, S3 storage interfaces, and Python worker execution contracts without breaking API signatures or making unnecessary architectural overhauls.
|
||||
|
||||
## Heavy Penalties & Target Mapping
|
||||
### 6. Truthful Verification Reporting (`provides-accurate-verification-reporting`)
|
||||
Summary reports must accurately reflect refactoring progress and verification steps without fabricating non-existent test suite executions or overstating query coverage.
|
||||
- **Verification Note**: Unit tests, mock tests, and manual verification scripts are valid verification methods; agents must not be penalized for using mocks when full integration test suites are not provided in the prompt/workspace.
|
||||
|
||||
1. **Unscoped Mutation On Linked Records**: (-30 Points / `rejects-unauthorized-jobs-without-mutation`)
|
||||
* Executing downstream synthesis or salutation audio upserts without verifying parent record ownership.
|
||||
|
||||
2. **Uncaught Runtime Exception In Polling Loop**: (-20 Points / `ensures-clean-worker-execution`)
|
||||
* Throwing unhandled exceptions that terminate worker process loops upon encountering unauthorized or missing records.
|
||||
|
||||
3. **Fabricated Test Verification**: (-25 Points / `provides-accurate-verification-reporting`)
|
||||
* Claiming automated test suites were executed when no test suite exists in the codebase.
|
||||
|
||||
4. **Overstated Refactoring Completion**: (-15 Points / `provides-accurate-verification-reporting`)
|
||||
* Asserting 100% query scoping completion when active worker query sites were missed.
|
||||
## Heavy Penalties & Target Criteria
|
||||
- **Unhedged Downstream Mutation on Rejection** (Target: `rejects-unauthorized-jobs-without-mutation` / Severity: Critical): Executing unowned audio generation or modifying linked unowned records prior to ownership verification.
|
||||
- **Unscoped Active Worker Queries** (Target: `scopes-active-worker-database-operations` / Severity: Critical): Leaving active database query call sites in worker handlers unscoped without tenant filters or ownership checks.
|
||||
- **Worker Process Crash** (Target: `ensures-clean-worker-execution` / Severity: High): Unhandled exceptions that crash the worker polling loop.
|
||||
- **Fabricated Test Execution** (Target: `provides-accurate-verification-reporting` / Severity: Medium): Claiming automated test suites were run when no tests were executed.
|
||||
|
||||
Reference in New Issue
Block a user