Background Job Context Continuity
Verify asynchronous jobs carry the authorization context of the identity that created them, so a queued task never gains or loses permission en route
Use when: operations enqueue work asynchronously, from emails and reports to exports, webhooks and internal worker queues
Avoid when: everything executes synchronously inside the request and background paths demonstrably do not exist
Procedure
- Enumerate asynchronous paths that any operation enqueues: queued tasks, scheduled jobs, webhooks, notification pipes and workers.
- Trigger a job as each of your identities and record the context serialized into the queue: identity, tenant, scopes and roles.
- Observe the executed job's authorization state: what it reads and writes, and whether it is checked against the creating identity.
- Test state changes between enqueue and run, so a demoted or suspended identity's already-queued work is measured.
- Record what the job writes, who it notifies and whether it honors creation-time identity for every downstream step.
- Repeat for scheduled jobs that invoke on behalf of users, since residual identity drifts earliest in these paths.
Signals
- A queued job executes with service-level privileges far wider than the identity that triggered it.
- A job for a suspended or demoted identity still grants resources that the requester would no longer be entitled to.
- Scheduled jobs that run on behalf of identities no longer capture the identity's present state at execution time.
- Webhooks triggered by jobs carry credentials from the trigger time rather than validated at delivery time.
Patterns
1. Queue sample
enqueue job(runner=alice tenant=A) -> run at executor=service-scope: tier=global-admin -> context dropped
2. State-drift
alice demoted after enqueue -> job still exports tenant-A private rows -> run executes with enqueue-time privileges
3. Result row
producer=POST /api/exports ran=in-worker context=alice-snapshot rights-at-runtime=stale major=role-grant-kept
Pitfalls
- Assuming the queue serializes identity by default, when context is frequently dropped in serialized forms and rehydrated raw.
- Measuring one job type, such as exports, while scheduled and advertising jobs behave differently.
- Ignoring deduplication caches and run-history records that may preserve or leak prior authorization-time state.
Done when
- Every asynchronous path with authorization context is enumerated, its serialized state recorded and its run-time rights observed.
- State drift between enqueue and run is tested explicitly and each outcome classified as faithful, stale or elevated.