JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Polymorphic has_many relationships linkage data skips authorization checks added to records_for
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Ruby
- Estrellas
- 2.3k
- Forks
- 546
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con JSONAPI::ResourceSerializer#foreign_key_types_and_values y Resource::_add_relationship, y luego sigue cómo se usa records_for para los registros de relaciones autorizados. Verifica que los datos de vinculación de los has_many polimórficos sigan la ruta de autorización a nivel de recurso y que los registros relacionados no autorizados ya no produzcan objetos de enlace.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- ruby
- Área
- api, authorization, backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100