Phoenix is safe where a plug pipeline enforces auth and unsafe where a socket or a route skips it. Test every route with no session cookie, and every LiveView handle_event with an id the current user does not own.
Where this class of bug actually lives in a Phoenix app
- Pipelines. A scope using
:apiinstead of:browser, or a route outside the:authenticatedpipeline, has no session check. - LiveView events.
handle_event("delete", %{"id" => id}, socket)trusts the client. The socket's assigned user is the only trustworthy identity. - Contexts without scoping.
Repo.get(Invoice, id)returns any row; scoping belongs in the context function. - Channels. A socket topic joined without an authorization check broadcasts another tenant's messages to any subscriber.
What to try first
- Request each route with no session and watch for a 200 or a LiveView mount instead of a redirect.
- Push a LiveView event with a foreign id using the browser console or a websocket client.
- Try joining a channel topic belonging to another tenant.
- Grep contexts for
Repo.getand check each call site for scoping.
A reproduction you can keep
LiveView events are ordinary websocket messages. A foreign id in the payload is the test:
# in the browser console on an authenticated LiveView page
const [view] = [...window.liveSocket.socket.roots.values()];
view.pushEvent("delete", {id: 1003});
# vulnerable: the event deletes another tenant's record
# fixed: the handler re-queries scoped to socket.assigns.current_user and no-opsWhat "fixed" has to look like
Every handle_event must re-fetch through a context scoped to socket.assigns.current_user and ignore ids that do not resolve, so a forged payload is a no-op rather than a 500 or a delete. Verify by pushing three foreign ids and confirming the record count does not move.
Where people get this wrong
- A LiveView that checks authorization on mount and not on every event is only protected for the first render.
Ectocasts accept every field in the changeset's cast list, which is easy to widen for a feature and never narrow again.- Phoenix's default error page in dev renders the full stack and assigns; make sure
devis never the reachable environment.
What Offense does here
Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.
Questions this page answers
Are LiveView events authenticated?
The socket is, if you check on mount. Individual events are not — each one has to authorize against socket.assigns.
Where do Phoenix apps usually leak tenancy?
In Repo.get/2 calls inside a context function that never filters by the current account.
Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.