JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Polymorphic has_many relationships linkage data skips authorization checks added to records_for
Nessuno ha ancora preso questa issue.
- Lingua principale
- Ruby
- Stelle
- 2.3k
- Fork
- 546
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I'm using a simple method of authorization which is being broken by link objects for polymorphic has many relationships.
I have a ResourceBase class derived from JSONAPI::Resource, which overrides records and records_for to only return authorized records. This was working fine until I added a polymorphic has many relationship to one of my resources. At which point a number of unauthorized link objects were appearing for the resource's polymorphic relationship.
The reason for this being that JSONAPI::ResourceSerializer#foreign_key_types_and_values makes a call directly to the resources underlying model for polymorphic relationships. This call skips the records_for call in which I have been performing my authorization.
foreign_key_types_and_values is the only place in which ResourceSerializer accesses the resource's underlying model leading me to believe that there should be a method on the JSONAPI::Resource which ResourceSerializer should be calling in this case.
A possible solution would be to:
- Change
foreign_key_types_and_valuesto call a method onResourceto retrieve the foreign keys and types, for both polymorphic and non-polymorphic relationships. - Change
Resource::_add_relationshipto create a new method on the resource for each polymorphic has many relationship. This method would return both the type and id of the related models making sure to do so by callingrecords_for.
I'll see if I can put together a PR for this, but thought I'd mention the bug and my suggested fix first.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con JSONAPI::ResourceSerializer#foreign_key_types_and_values e Resource::_add_relationship, quindi segui come viene usato records_for per i record delle relazioni autorizzati. Verifica che i dati di linkage degli has_many polimorfici seguano il percorso di autorizzazione a livello di risorsa e che i record correlati non autorizzati non producano più oggetti link.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- ruby
- Ambito
- api, authorization, backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100