Install
$ agentstack add skill-lonsdale201-wp-agent-skills-br-owned-resource-guards ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
better-route: Owned resource guards
Use ownership guards when authentication is not enough. A valid token proves identity; an ownership guard proves the requested object belongs to that identity.
Route-level guard
use BetterRoute\Middleware\Auth\OwnershipGuardMiddleware;
$guard = new OwnershipGuardMiddleware(
ownerResolver: static function ($context): ?int {
$id = (int) $context->request->get_param('id');
return my_resource_owner_id($id);
},
bypassCapability: 'manage_options'
);
$router->get('/account/records/(?P\d+)', $handler)
->middleware([$jwt, $guard])
->protectedByMiddleware('bearerAuth');
OwnershipGuardMiddleware checks RequestContext::$attributes['auth']['userId'], then subject, then get_current_user_id(). It returns 404 not_found by default on denial to avoid disclosing object existence.
Resource DSL policy
use BetterRoute\Resource\OwnedResourcePolicy;
Resource::make('records')
->policy(OwnedResourcePolicy::currentUserOwns(
ownerResolver: static fn (int $id): ?int => my_resource_owner_id($id),
bypassCapability: 'manage_options'
));
Use this when Resource-generated get, update, or delete routes need owner checks. For list routes, also filter the query itself by current user; list permission alone is not a data filter.
Rules
- Run auth middleware before the ownership guard.
- Never rely on client-sent owner/customer/user IDs.
- Resolve ownership server-side from the resource ID.
- Use a bypass capability only for real admin/integration routes.
- Prefer
404for customer/user routes,403only when the API intentionally exposes resource existence. - For write routes, combine with optimistic lock or atomic idempotency when the operation has side effects.
Source refs
libraries/better-route/src/Middleware/Auth/OwnershipGuardMiddleware.phplibraries/better-route/src/Resource/OwnedResourcePolicy.phplibraries/better-route/src/Resource/ResourcePolicy.php
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Lonsdale201
- Source: Lonsdale201/wp-agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.