JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Polymorphic has_many relationships linkage data skips authorization checks added to records_for

Đang mở
#685 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Type: Bug
Ngôn ngữ chính
Ruby
Star
2.3k
Fork
546
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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:

  1. Change foreign_key_types_and_values to call a method on Resource to retrieve the foreign keys and types, for both polymorphic and non-polymorphic relationships.
  2. Change Resource::_add_relationship to 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 calling records_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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với JSONAPI::ResourceSerializer#foreign_key_types_and_values và Resource::_add_relationship, sau đó theo dõi cách records_for được sử dụng cho các bản ghi quan hệ đã được cấp quyền. Xác minh rằng dữ liệu linkage của has_many đa hình tuân theo đường dẫn cấp quyền ở cấp tài nguyên và rằng các bản ghi liên quan không được cấp quyền không còn tạo ra các đối tượng liên kết.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
ruby
Lĩnh vực
api, authorization, backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.