JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Disabling JSONAPI.configuration.raise_if_parameters_not_allowed allows you to remove forbidden relationships

オープン
#954 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

lib/jsonapi/request_parser.rb の、issue に記載された parse_params パスから始め、次に update_relationship のエントリーポイントを追跡します。指定された controller テストシナリオを使って、禁止された relationship によって既存の author がクリアされず、リクエストが bad_request を返すことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
ruby
領域
api
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。