securing-collections skill
Doctrine eklentileriyle global sorgu filtreleri ve iç içe geçmiş kaynak sahipliği doğrulaması için link handler'lar kullanarak API Platform koleksiyonlarını güvenli hale getirir.
- GitHub yıldızları
- 29
- Dosyalar
- 1
- Son commit
- 22 Eki 2026
- Lisans
- —
- İzin verilen araçlar
- —
securing-collections skill ne işe yarar?
Doctrine eklentileriyle global sorgu filtreleri ve iç içe geçmiş kaynak sahipliği doğrulaması için link handler'lar kullanarak API Platform koleksiyonlarını güvenli hale getirir.
Özet, skill'in SKILL.md dosyasından oluşturuldu.
securing-collections skilli hakkında
Bu SKILL, API Platform içerisinde çok kiracılı (multi-tenant) izolasyon ve veri gizliliği uygulanmasını sağlar. Geliştiriciler, kullanıcıların yalnızca kendi organizasyonlarına veya hesaplarına ait kayıtları görmelerini sağlamak için veri erişimini sorgu seviyesinde kısıtlayabilirler. Bu, iki temel mekanizma ile gerçekleştirilir: global sorgu filtreleri için Doctrine eklentileri ve iç içe geçmiş kaynak URI'lerinde sahipliği doğrulamak için link handler'lar.
Bir agent; bir proje soft-delete filtrelemesi, kullanıcıya göre sorgu sınırlandırma veya hesaplar ve posta kutuları gibi hiyerarşik yolların güvenliğini sağlama gerektirdiğinde bu SKILL'i yüklemelidir. Symfony kullanıcıları için bu SKILL, eklentiler için autowiring kullanarak hem Doctrine ORM hem de MongoDB ODM için uygulamalar sunar. Laravel ortamları için ise Eloquent QueryExtensionInterface kullanımı ve Eloquent modelleri için gereken özel Options yapılandırması hakkında rehberlik sağlar. SKILL, veriler çekilmeden önce alttaki QueryBuilder veya aggregation pipeline'ı değiştirerek yetkisiz veri ifşasını önleyen yapılandırılmış kod desenleri üretir.
Bir agent bununla neler yapabilir
- 1Çok kiracılı veri izolasyonunu zorunlu kılınBelirli bir kaynak için yapılan her sorgunun otomatik olarak kullanıcının mevcut organizasyonuyla sınırlandırılması için global bir filtre uygulayın.
- 2Soft-delete işlevselliğini uygulayınSilindi olarak işaretlenmiş kayıtları tüm koleksiyon ve öğe sorgularından otomatik olarak gizleyin.
- 3İç içe geçmiş kaynak URI'lerini güvenli hale getirinİç içe geçmiş API yollarına erişirken, bir alt kaynağın doğru üst kaynağa ait olduğunu doğrulayın.
- 4Laravel Eloquent filtrelerini yapılandırınÖzel QueryExtensionInterface ve service tagging gereksinimlerini kullanarak Laravel projeleri için global sorgu eklentileri kurun.
Skill'in SKILL.md dosyasından yazılmıştır. Her kullanım durumu oradaki bir alıntı ile kontrol edilir.
securing-collections skill nasıl kurulur
Her komut, skill klasörünü istemcinin skills dizinine kopyalar. Yüklemek için istemciyi yeniden başlatın veya yeni bir oturum başlatın.securing-collections skill'ini Eklenti uygulamasına kur
/plugin marketplace add api-platform/skillset /plugin install api-platform@api-platform-skillset
securing-collections skill'ini Claude Code uygulamasına kur
~/.claude/skills/securing-collections/SKILL.md
$ npx degit api-platform/skillset/skills/securing-collections ~/.claude/skills/securing-collectionssecuring-collections skill'ini Claude Code (project) uygulamasına kur
.claude/skills/securing-collections/SKILL.md
$ npx degit api-platform/skillset/skills/securing-collections .claude/skills/securing-collectionssecuring-collections skill'ini Codex uygulamasına kur
~/.agents/skills/securing-collections/SKILL.md
$ npx degit api-platform/skillset/skills/securing-collections ~/.agents/skills/securing-collectionssecuring-collections skill'ini Gemini CLI uygulamasına kur
~/.gemini/skills/securing-collections/SKILL.md
$ npx degit api-platform/skillset/skills/securing-collections ~/.gemini/skills/securing-collectionssecuring-collections skill'ini Claude.ai uygulamasına kur
npx degit api-platform/skillset/skills/securing-collections securing-collections && zip -r securing-collections.zip securing-collections # claude.ai → Customize → Skills → + → Create skill → Upload a skill → securing-collections.zip
Otomatik kontroller
Çalıştırıldı 16 Kas 2026Tam rapor →Henüz doğrulanmadı. Bir skill için 80 puan, ciddi bulgu olmaması ve kontrol için yeterli veri gerekir. Kontroller nasıl çalışır · Daha fazla puan için nelerin düzeltileceği
- Kaynak deposu bağlantılı ve erişilebilirapi-platform/skillset/skills/securing-collections is public and reachablegithub.com/api-platform/skillset/tree/HEAD/skills/securing-c ↗Geçti
- Açık kaynak lisansı (OSI)No licenseBulgu
- Son bir yıl içinde commit veya sürüm mevcutLast commit 2026-10-22github.com/api-platform/skillset/commits ↗Geçti
- Betiklerde indir-çalıştır veya kimlik bilgisi hırsızlığı yokNo scripts in the skill folderGeçti
- SKILL.md içinde gizli talimat yokNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/api-platform/skillset/blob/HEAD/skills/securing-c ↗Geçti
- Önceden izin verilen araçlar sınırlıNo pre-approved tools; the agent asks before using onegithub.com/api-platform/skillset/blob/HEAD/skills/securing-c ↗Geçti
- SKILL.md, Agent Skills biçimine uyuyorValid name and description; says when to use it; 238 linesgithub.com/api-platform/skillset/blob/HEAD/skills/securing-c ↗Geçti
SKILL.md
GitHub'da görüntüleSecuring Collections
Two mechanisms restrict what data users can access at the query level.
Doctrine Extensions (Global Query Filters)
Extensions automatically modify every query for a resource class. Use them for:
- Multi-tenant isolation (filter by organization/user)
- Hiding soft-deleted records
- Any filter that must apply to ALL queries (item + collection)
ORM Extension
<?php
namespace App\Extension;
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
final class AccountExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
{
public function __construct(private UserHelper $userHelper) {}
public function applyToCollection(QueryBuilder $qb, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
$this->addWhere($qb, $resourceClass);
}
public function applyToItem(QueryBuilder $qb, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, ?Operation $operation = null, array $context = []): void
{
$this->addWhere($qb, $resourceClass);
}
private function addWhere(QueryBuilder $qb, string $resourceClass): void
{
if (Account::class !== $resourceClass) {
return;
}
$user = $this->userHelper->getUser();
if (!$user) {
return;
}
$rootAlias = $qb->getRootAliases()[0];
$qb->andWhere(sprintf('%s.organization = :org', $rootAlias))
->andWhere(sprintf('%s.isDeleted = :deleted', $rootAlias))
->setParameter('org', $user->getCurrentOrganization())
->setParameter('deleted', false);
}
}
Extensions are auto-registered by Symfony's autowiring. No service tag needed.
MongoDB ODM Extension
Same structure as the ORM version; only the interfaces, the apply-method
signatures, and the query API differ. Implement
AggregationCollectionExtensionInterface / AggregationItemExtensionInterface
(from ApiPlatform\Doctrine\Odm\Extension), and build the filter on a
Doctrine\ODM\MongoDB\Aggregation\Builder instead of a QueryBuilder:
public function applyToCollection(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
{
$this->applyFilters($aggregationBuilder, $resourceClass);
}
// applyToItem adds `array $identifiers` after $resourceClass; both delegate here:
private function applyFilters(Builder $aggregationBuilder, string $resourceClass): void
{
if (Account::class !== $resourceClass) {
return;
}
$user = $this->userHelper->getUser();
if (!$user) {
return;
}
$aggregationBuilder->match()
->field('isDeleted')->equals(false)
->field('organization')->equals($user->getCurrentOrganization()->getId());
}
The ODM apply methods take string $resourceClass directly (no
QueryNameGenerator) and receive $context by reference.
Link Handlers (Nested Resource Security)
Link handlers validate parent resource ownership for nested URIs like /accounts/{accountId}/mailboxes/{mailboxId}/messages.
MongoDB ODM Link Handler
<?php
namespace App\Extension;
use ApiPlatform\Doctrine\Odm\State\LinksHandlerInterface;
use Doctrine\ODM\MongoDB\Aggregation\Builder;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class MessageLinkHandler implements LinksHandlerInterface
{
public function __construct(
private readonly UserHelper $userHelper,
private readonly MailboxRepository $mailboxRepository,
) {}
public function handleLinks(Builder $aggregationBuilder, array $uriVariables, array $context): void
{
$user = $this->userHelper->getUser() ?? throw new AccessDeniedHttpException();
// Validate parent resource exists
$mailbox = $this->mailboxRepository->find($uriVariables['mailboxId'])
?? throw new NotFoundHttpException();
// Validate parent belongs to correct account
if ($mailbox->account->getId() !== ($uriVariables['accountId'] ?? null)) {
throw new NotFoundHttpException();
}
// Validate user has access to this resource tree
if ($mailbox->organization?->getId() !== $user->getCurrentOrganization()?->getId()) {
throw new AccessDeniedHttpException();
}
// Apply query filters
$aggregationBuilder->match()
->field('isDeleted')->equals(false)
->field('mailbox')->equals($mailbox);
// Filter individual item if ID provided
if (isset($uriVariables['id'])) {
$aggregationBuilder->match()
->field('id')->equals($uriVariables['id']);
}
}
}
Assigning to Resource
use ApiPlatform\Doctrine\Odm\State\Options;
#[ApiResource(
operations: [
new Get(
uriTemplate: '/accounts/{accountId}/mailboxes/{mailboxId}/messages/{id}',
uriVariables: ['accountId', 'mailboxId', 'id'],
stateOptions: new Options(
handleLinks: MessageLinkHandler::class,
documentClass: Message::class,
),
),
]
)]
When to Use Which
| Pattern | Use Case |
|---|---|
| Extension | Global filters: multi-tenant isolation, soft-delete, applies to ALL queries for a resource |
| Link Handler | Nested resources: validate parent ownership, scope child queries to parent |
security attribute |
Per-operation checks on already-fetched objects: security: 'object.user == user' |
These mechanisms stack: an extension filters the query, a link handler scopes it to the parent, and security validates the final object.
Laravel (Eloquent)
The two mechanisms exist on Laravel too, but there are no Doctrine extensions.
The global-query-filter equivalent is ApiPlatform\Laravel\Eloquent\Extension\QueryExtensionInterface
— one apply() method covering both item and collection (the Eloquent providers run
it for every query):
<?php
namespace App\Extension;
use ApiPlatform\Laravel\Eloquent\Extension\QueryExtensionInterface;
use ApiPlatform\Metadata\Operation;
use Illuminate\Database\Eloquent\Builder;
final class AccountExtension implements QueryExtensionInterface
{
public function __construct(private readonly UserHelper $userHelper) {}
public function apply(Builder $builder, array $uriVariables, Operation $operation, $context = []): Builder
{
if (Account::class !== $operation->getClass() || !($user = $this->userHelper->getUser())) {
return $builder;
}
return $builder
->where('organization_id', $user->getCurrentOrganization()->id)
->where('is_deleted', false);
}
}
Tag it so the providers pick it up by binding to the QueryExtensionInterface tag in
a service provider ($this->app->tag([AccountExtension::class], QueryExtensionInterface::class));
there is no Symfony autowiring.
For nested-resource ownership, implement
ApiPlatform\Laravel\Eloquent\State\LinksHandlerInterface —
handleLinks(Builder $builder, array $uriVariables, array $context): Builder —
returning the scoped builder (it operates on an Eloquent Builder, not an aggregation
pipeline). Assign it with the Eloquent Options:
use ApiPlatform\Laravel\Eloquent\State\Options;
new Get(
uriTemplate: '/accounts/{accountId}/messages/{id}',
uriVariables: ['accountId', 'id'],
stateOptions: new Options(handleLinks: MessageLinkHandler::class, modelClass: Message::class),
)
Note Eloquent Options uses modelClass: (not documentClass:/entityClass:).
Per-operation security expressions and Laravel policies (viewAny/view/
create/update/delete, or an explicit policy: on an operation) layer on top —
see the operations skill's Laravel section.
Bu becerideki dosyalar
1securing-collections skill soruları
securing-collections skill'ini Claude Code uygulamasına nasıl kurarım?
npx degit api-platform/skillset/skills/securing-collections ~/.claude/skills/securing-collections komutunu çalıştırın. Claude Code, skill'leri ~/.claude/skills (tüm projeler) veya .claude/skills (tek proje) konumundan yükler ve açıklaması görevle eşleştiğinde skill'i kullanır.
securing-collections skill'ini hangi istemciler kullanabilir?
Agent Skills biçimini okuyan her istemci: Claude Code, Codex, Gemini CLI ve claude.ai (ZIP olarak yükleyin). Skill içindeki betikler yalnızca istemcinin kod çalıştırmaya izin verdiği yerlerde çalışır.
API Platform ile Laravel'de global sorgu filtrelerini nasıl uygularım?
QueryExtensionInterface'i uygulayın ve service provider içinde etiketleyin; çünkü Laravel, Symfony'nin bu işlem için kullandığı autowiring desteğine sahip değildir.
Bu mekanizmaları birlikte kullanabilir miyim?
Evet, üst üste binecek şekilde tasarlanmışlardır: bir eklenti sorguyu filtreler, bir link handler sorguyu üst kaynağa göre sınırlar ve güvenlik nitelikleri nihai nesneyi doğrular.