Skip to content

WS005 · Laravel container singleton with mutable state

Default severity: HIGH · Framework: laravel

A singleton() binding is resolved once and then reused. Octane keeps the container between requests, so the same instance — and everything written into it — is handed to every request the worker serves.

  • Consider $this->app->scoped(): Octane discards scoped instances between requests. Check first what else resolves this class — anything that outlives a request and took it through the constructor keeps the instance it already has, so the binding changes while that consumer does not.
  • Or make the service immutable and pass the per-request values in as method arguments. That removes the question of lifetime instead of answering it.
  • If the binding must stay a singleton, reset its state in a RequestReceived listener.
Terminal window
vendor/bin/worker-safety rules WS005

Use a targeted suppression or a baseline only after reviewing the value’s origin and lifetime. Changing an assignment elsewhere may not invalidate an existing property-level suppression.