api-platform-security
Skill2 starsChanged 6 months agoMITView on GitHub
Secure an API Platform 4.3 application end-to-end — operation-level security (`security`, `securityPostDenormalize` with `previous_object`, `securityPostValidation`, `throw_on_access_denied`), property-level security (`#[ApiProperty(security: ...)]`), Doctrine collection extensions for owner-scoped lists, voters, UUID/ULID identifiers (anti-enumeration), JWT authentication with LexikJWTAuthenticationBundle (keys, refresh tokens, HttpOnly cookies, RS256), OIDC alternative, CORS via nelmio/cors-bundle. Includes the 4.3 perf optimization where `isGranted` is evaluated before the state provider when `object` is not referenced. Trigger when wiring `security`, writing a voter, hiding an admin-only field, setting up JWT, fixing CORS, or auditing for security gaps.
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-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
- symfony-votersSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
The file
Files
API Platform 4.3 — Security
Use when
- Wiring
security/securityPostDenormalize/securityPostValidationon operations. - Writing or testing a voter (
POST_VIEW,POST_EDIT, etc.). - Filtering a collection by owner via a Doctrine extension.
- Setting up JWT authentication (Lexik) or OIDC.
- Configuring CORS for public / partner consumers.
- Switching identifiers to UUID v7 or ULID to remove enumeration risk.
Default workflow
- Apply
securityper operation. Fail closed — nosecurity:means public, only by design. - Decide between expression (simple) and Voter (complex). Cross more than one condition → Voter.
- For mutations that mutate ownership, use
securityPostDenormalizewithprevious_objectto enforce invariants. - For each sensitive property, decide: group split,
#[ApiProperty(security: ...)], or both. - Identifiers:
Uuid::v7()/Ulidon every public resource. No sequential IDs.
Guardrails
- Fail secure. Anything not explicitly public is
is_granted('ROLE_USER')minimum. securityMessageon every guarded operation — explicit feedback, no debug leakage.extraProperties: ['throw_on_access_denied' => true]— without it, an unauthorized field change is silently dropped instead of throwing 403.- Never log JWT contents. JWT is readable; no PII in claims.
- No
*in CORS whenallow_credentials: true. List the explicit origins. - Tests cover refusal AND acceptance. Both branches matter.
Progressive disclosure
SKILL.mdlists the posture and decision tree.reference.mdcarries the full patterns: operation security expressions, voters, query extensions, property security, UUID/ULID, JWT (Lexik) end-to-end (keys, security.yaml, Swagger UI, refresh tokens, storage), OIDC alternative, CORS configuration, performance note 4.3.
Output contract
- Each operation has an explicit
security(or a documented public exception). - Voters tested in isolation (
./vendor/bin/phpunit --filter=Voter). - Collection queries filtered through a
QueryCollectionExtensionInterface+QueryItemExtensionInterface. - Identifiers use UUID v7 / ULID where applicable.
- JWT / OIDC + CORS configurations match the published examples.
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.

