JSON:API: request documents with no `data`, no `type` or a wrong `type` are accepted with 201
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 62/100
Hướng nghiên cứu
Start in src/JsonApi/Serializer, where JsonApi\Serializer\ItemNormalizerTrait::denormalize() reads $data['data']['attributes'] ?? [] and $data['data']['relationships'] ?? [] without checking the document shape. Reproduce with the request bodies in the table (for example "Y", {"title":"A"} and a mismatched type) against a POST /novels operation. Done means malformed documents return 400 Bad Request, and a POST whose type does not match the endpoint returns 409 Conflict, with the existing JSON:API tests still passing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
API Platform version(s) affected
4.4.4
Description
The JSON:API denormalizer does not check the structure of the request document. A body that is not a valid JSON:API document is accepted, and the resource is created with its default values.
The spec requires:
- the top level of a request document is an object with a
datamember (document structure), datais a resource object with atypemember, andattributesis an object (resource objects),- "A server MUST return
409 Conflictwhen processing aPOSTrequest in which the resource object'stypeis not among the type(s) that constitute the collection represented by the endpoint" (creating resources).
JsonApi\Serializer\ItemNormalizerTrait::denormalize() reads $data['data']['attributes'] ?? [] and $data['data']['relationships'] ?? [], and it does not check the other members.
How to reproduce
#[ApiResource(operations: [
new Get(provider: [self::class, 'provide']),
new Post(processor: [self::class, 'process']),
])]
final class Novel
{
public int $id = 1;
public string $title = 'Dune';
public static function provide(): self { return new self(); }
public static function process(self $data, Operation $operation): self { return $data; }
}
Each of these POST /novels bodies answers 201 Created:
| Body | Problem |
|---|---|
"Y" |
not an object |
42 |
not an object |
{"title":"A"} |
no data member |
{"data":"x"} |
data is not a resource object |
{"data":{"type":"Novel","attributes":["x"]}} |
attributes is not an object |
{"data":{"attributes":{"title":"A"}}} |
no type member |
{"data":{"type":"Author","attributes":{"title":"A"}}} |
type does not match the endpoint |
Response for "Y":
{"data":{"id":"/novels/1","type":"Novel","attributes":{"_id":1,"title":"Dune"}}}
A validation constraint on a required property hides the problem in some cases, but a resource with optional properties or defaults is created from any body.
Expected:
- A body that is not a JSON:API document, or has no
dataobject, notypeor a non-objectattributes/relationships:400 Bad Request. - A
typethat does not match the resource onPOST:409 Conflict.
Additional Context
Checked on api-platform/core v4.4.4, Symfony 7.4, PHP 8.5, in an empty Symfony app. The related code in src/JsonApi/Serializer is the same on main, except for the error status cast (#8366).
The app has only FrameworkBundle, TwigBundle and ApiPlatformBundle, with this config:
$c->extension('api_platform', [
'mapping' => ['paths' => ['%kernel.project_dir%/src/ApiResource']],
'formats' => ['jsonapi' => ['application/vnd.api+json']],
'error_formats' => ['jsonapi' => ['application/vnd.api+json'], 'jsonproblem' => ['application/problem+json']],
'doctrine' => ['enabled' => false],
]);
All requests send Accept: application/vnd.api+json and, when they have a body, Content-Type: application/vnd.api+json. The responses are from the prod environment.
- Ngôn ngữ chính
- PHP
- Star
- 2.6k
- Fork
- 989
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 106
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
api-platform/core#8744 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Có thể đã có người làm @ousamabenyounes đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 80/100
api-platform/core#8701 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Json-Schema] Nested resources lost externalDoc and description dataCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8721 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: 404/405 router errors are empty, and error objects have a non-spec `type` memberCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
api-platform/core#8704 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: relations set through the constructor reject spec resource linkage (`relationships.<name>.data`)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8702 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của api-platform/core
Issue tương tự
-
Successful AUTHORISATION for a transaction already set to "failed" is marked done without paying itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Adyen/adyen-shopware6#895 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
not confirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
MagnaCapax/PMSS#1119 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Monit: poll time validation rejects "/", blocking the cron step syntax recommended by Monit 6Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.5] Admin GraphQL attributeValues.value reads price from integer_value instead of float_valueĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
bagisto/bagisto-api#54 ·