AgentStack
SKILL verified MIT Self-run

Br Owned Resource Guards

skill-lonsdale201-wp-agent-skills-br-owned-resource-guards · by Lonsdale201

Add better-route 0.5.0 ownership checks for user-owned REST resources. Use when a route or Resource DSL endpoint must ensure the authenticated user owns the order, record, token, subscription, membership, profile object, or other per-user object. Triggers on OwnershipGuardMiddleware, OwnedResourcePolicy, currentUserOwns, ownerResolver, bypassCapability, and customer-owned or user-owned API routes.

No reviews yet
0 installs
6 views
0.0% view→install

Install

$ agentstack add skill-lonsdale201-wp-agent-skills-br-owned-resource-guards

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No 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.

Are you the author of Br Owned Resource Guards? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

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 404 for customer/user routes, 403 only 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.php
  • libraries/better-route/src/Resource/OwnedResourcePolicy.php
  • libraries/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.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.