Unsafe GET Actions, Alternate Transports, and Login CSRF
Find writes reachable through GET, inspect the chosen GraphQL operation, and follow a separate unwanted-login example.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
An invitation service carefully protects its POST route. Then someone adds a GET route that reaches the same invitation code. A browser can now be asked to follow a link that changes the team.
Start with that one mistake: a read-style request reaches a write. We'll inspect which GraphQL operation is selected and stop mutations before a GET request executes them.
The second example is login CSRF, which changes which account a browser signs in to. It has a different journey from changing an invitation in an existing session, so we'll work through it separately.
First journey: a GET request must not change the team
HTTP defines GET as a safe method: the client is not asking for an application state change. Frameworks, browsers, crawlers, link previews, caches, and users rely on this expectation. A route called preview or query is not safe merely because its name sounds read-only. Follow it to its actual side effects.
// Unsafe outline: a complete document is accepted on GET.
app.get('/graphql', async (req, res) => {
const actor = requireSession(req);
const result = await graphql({
schema,
source: req.query.query,
variableValues: JSON.parse(req.query.variables || '{}'),
operationName: req.query.operationName,
contextValue: { actor },
});
res.json(result);
});
The executor can select a mutation from that document. The resolver can correctly require an owner and still execute an unwanted request under a real owner's session. Authentication, authorization, and intent remain separate checks.
The same authorized resolver can be reached through differently protected transports.
Select. Resolve the document and operationName instead of trusting a route label.
query ReadTeam { team(id: "fixture") { name } }
mutation Invite { inviteOwner(teamId: "fixture", email: "a@example.test") { id } }
Gate. A selected mutation is rejected on GET before resolver execution.
if (method === "GET" && operation.operation !== "query") {
return methodNotAllowed();
}
Authorize. Protected POST still needs intent and team-owner permission.
enforceCsrf(request);
requireTeamOwner(actor, teamId);
return createPendingInvite(teamId, email);
Review question: A stronger POST does not repair a weaker GET reaching the same action.