JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Disabling JSONAPI.configuration.raise_if_parameters_not_allowed allows you to remove forbidden relationships
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
If raise_if_parameters_not_allowed is set to false, then something strange happens.
In https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/request_parser.rb#L237 the params are first filtered using parse_params. Suppose I have a model with an author relationship (like in the tests) that is optional (so presence is not validated) but remove the author from updatable_fields:
class Post < ActiveRecord::Base
belongs_to :author, optional: true
end
class PostResource < JSONAPI::Resource
has_one :author
def self.updatable_fields(context)
super - [:author]
end
end
If I send an update_relationship request to the PostResource, then any relationship data I send to the PostResource gets set to nil. The post's author is set to nil and, since that is a valid value, the update is saved to the database. In other words, the following controller test would fail:
def test_update_relationship_to_one_forbidden_relationship_filtered_parameter
JSONAPI.configuration.raise_if_parameters_not_allowed = false
refute_nil Post.find(1).author
set_content_type_header!
put :update_relationship, params: {post_id: 1, relationship: 'author', data: {anything: "really"}}
assert_response :bad_request
refute_nil Post.find(1).author
ensure
JSONAPI.configuration.raise_if_parameters_not_allowed = true
end
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in lib/jsonapi/request_parser.rb beim im Issue beschriebenen parse_params-Pfad und verfolge dann den Einstiegspunkt update_relationship. Verwende das benannte Controller-Testszenario, um zu überprüfen, dass eine nicht erlaubte Beziehung den bestehenden Autor nicht löscht und dass die Anfrage bad_request zurückgibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100