symfony-voters
Skill2 starsChanged 6 months agoMITView on GitHub
Implement Symfony Voters for fine-grained, object-level authorization — `Voter::supports($attribute, $subject)` filtering by attribute prefix (`POST_VIEW`, `POST_EDIT`, `POST_DELETE`, `POST_CREATE`) and subject class, `Voter::voteOnAttribute($attribute, $subject, $token)` returning the decision based on user roles and object state (ownership, publication status). Wire via `is_granted('POST_VIEW', $post)` from controllers, `#[IsGranted('POST_EDIT', subject: 'post')]` attributes, API Platform operation `security:` expressions, or programmatically through `Symfony\\Bundle\\SecurityBundle\\Security::isGranted()`. Test each voter in isolation with PHPUnit, asserting permit / deny / abstain branches. Trigger on "voter", "authorization", "object-level permissions", "ownership check", or "is_granted not granular enough".
In this repository52 other files it gives its agents.
- api-platform-dto-resourcesSkill
- api-platform-errorsSkill
- api-platform-file-uploadSkill
- api-platform-filtersSkill
- api-platform-identifiersSkill
- api-platform-mcpSkill
- api-platform-mutatorsSkill
- api-platform-openapiSkill
- api-platform-paginationSkill
- api-platform-performanceSkill
- api-platform-resilienceSkill
- api-platform-resourcesSkill
- api-platform-securitySkill
- api-platform-serializationSkill
- api-platform-state-processorsSkill
- api-platform-state-providersSkill
- api-platform-testsSkill
- api-platform-upgradeSkill
- api-platform-userSkill
- api-platform-versioningSkill
- bootstrap-checkSkill
- brainstormingSkill
- config-env-parametersSkill
- controller-cleanupSkill
- cqrs-and-handlersSkill
- daily-workflowSkill
- doctrine-batch-processingSkill
- doctrine-fetch-modesSkill
- doctrine-fixtures-foundrySkill
- doctrine-migrationsSkill
- doctrine-relationsSkill
- doctrine-transactionsSkill
- effective-contextSkill
- executing-plansSkill
- functional-testsSkill
- interfaces-and-autowiringSkill
- makefile-disciplineSkill
- messenger-retry-failuresSkill
- ports-and-adaptersSkill
- quality-checksSkill
- rate-limitingSkill
- runner-selectionSkill
- strategy-patternSkill
- symfony-cacheSkill
- symfony-messengerSkill
- symfony-schedulerSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 26
Test each voter in isolation with PHPUnit — permit / deny / abstain.
- Very specific: line 29
Fail closed: If supports() returns false, the voter abstains.
- Distinctive: line 30
One Voter per resource type: Keep the file small and the matrix readable.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Symfony Voters
Use when
- A
security:expression on an API Platform operation becomes longer than one boolean clause. - The authorization depends on the object state (owner, published, status).
- Different actions on the same resource need different permission rules.
- You want to test the authorization logic in isolation from controllers / providers.
Default workflow
- Define the attribute vocabulary (
POST_VIEW,POST_EDIT,POST_DELETE,POST_CREATE). - Implement a
Voterwithsupports()returningtrueonly for the relevant attribute + subject combination. - Implement
voteOnAttribute()returningtrueonly when the action is allowed. - Wire
is_granted('POST_VIEW', $post)in controllers, API operations, or Twig templates. - Test each voter in isolation with PHPUnit — permit / deny / abstain.
Guardrails
- Fail closed. If
supports()returnsfalse, the voter abstains. If it supports the attribute but the action is not granted, returnfalse. - One Voter per resource type. Keep the file small and the matrix readable.
- Inject
Security, never the request — voters must work outside the HTTP cycle. - Test every permission matrix entry. Permit, deny, abstain (when applicable).
- No business logic in voters — they read state and decide. Mutations belong elsewhere.
Progressive disclosure
SKILL.mdcovers posture and rules.reference.mdcarries the full Voter implementation pattern, integration recipes (API Platform, controller#[IsGranted], Twig), naming conventions, and isolated-testing pattern.
Output contract
- A
src/Security/Voter/<Resource>Voter.phpfile per resource type. is_granted('<RESOURCE>_<ACTION>', $subject)used at the integration points.- A
tests/Security/Voter/<Resource>VoterTest.phpcovering every attribute × scenario combination.
References
reference.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

