#62717 closed defect (bug) (invalid)
POST request to pages returns 200 or 404
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 6.7.1 |
| Component: | HTTP API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
When we send a POST request to a regular page via cURL with no data/body, we get 200 and a response containing the page content just as we would with GET.
When we send POST requests with arbitrary data, however, we get either 404 or 200 depending on the request body.
Is this an inconsistency to be fixed or just undocumented, but intended, behaviour?
Change History (9)
#2
in reply to:
↑ 1
@
18 months ago
This is very helpful to know – thank you @abcd95!
Empty POST requests are treated as GET requests, returning a 200 status with page content.
If this is intended to be used for cache invalidation, I hope there’s a way to prevent POST flood cache bypass attacks.
#3
@
10 months ago
- Resolution set to invalid
- Status changed from new to closed
As the page responses are not handled by the HTTP API, I am closing this ticket as invalid.
This ticket was mentioned in PR #11218 on WordPress/wordpress-develop by @adamsilverstein.
3 months ago
#5
- Keywords has-patch has-unit-tests added
## Summary
When uploading images via the REST API with generate_sub_sizes set to false, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with rest_upload_image_type_not_supported, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes.
This PR adds a check in WP_REST_Attachments_Controller::create_item_permissions_check() to skip the server-side image editor support check when generate_sub_sizes is explicitly false.
## Changes
class-wp-rest-attachments-controller.php: After thewp_prevent_unsupported_mime_type_uploadsfilter is applied, check ifgenerate_sub_sizesisfalseand bypass the image editor support check if so.rest-attachments-controller.php(tests): Two new tests:test_upload_unsupported_image_type_skipped_when_not_generating_sub_sizes— verifies upload succeeds withgenerate_sub_sizes=falsetest_upload_unsupported_image_type_enforced_when_generating_sub_sizes— verifies upload still fails withgenerate_sub_sizes=true
## Related
- Gutenberg PR: https://github.com/WordPress/gutenberg/pull/76371
- Gutenberg Issue: https://github.com/WordPress/gutenberg/issues/76369
- Trac: https://core.trac.wordpress.org/ticket/62717
## Test Plan
- [ ] Run PHP tests:
vendor/bin/phpunit tests/phpunit/tests/rest-api/rest-attachments-controller.php --filter="test_upload_unsupported_image_type" - [ ] Verify the two new tests pass and existing tests still pass
@adamsilverstein commented on PR #11218:
3 months ago
#6
## Proposed SVN Commit Message
Media: Skip server image support check when not generating sub-sizes. When uploading images via the REST API with `generate_sub_sizes` set to `false`, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with `rest_upload_image_type_not_supported`, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes. Skip the server-side image editor support check in `WP_REST_Attachments_Controller::create_item_permissions_check()` when `generate_sub_sizes` is explicitly `false`. See also https://github.com/WordPress/gutenberg/issues/76369 and https://github.com/WordPress/gutenberg/pull/76371. Props adamsilverstein, westonruter, andrewserong. Fixes #64836. See #62717.
@adamsilverstein commented on PR #11218:
3 months ago
#7
## Proposed SVN Commit Message
Media: Skip server image support check when not generating sub-sizes. When uploading images via the REST API with `generate_sub_sizes` set to `false`, the server still checks whether the image editor supports the uploaded image format. This causes uploads of formats like AVIF to fail with `rest_upload_image_type_not_supported`, even though the client is handling all image processing and the server doesn't need to generate any sub-sizes. Skip the server-side image editor support check in `WP_REST_Attachments_Controller::create_item_permissions_check()` when `generate_sub_sizes` is explicitly `false`. See also https://github.com/WordPress/gutenberg/issues/76369 and https://github.com/WordPress/gutenberg/pull/76371. Props adamsilverstein, westonruter, andrewserong. Fixes #64836. See #62717.
@mukesh27 commented on PR #11218:
3 months ago
#8
Mark ready for commit
Hey @prestonwordsworth, Thanks for bringing this up!
While I would be able to suggest better if the data being sent was provided, with the information given, I can see that the behavior you're observing is the expected implementation.
Empty POST requests are treated as GET requests, returning a 200 status with page content. When POST requests include data, WordPress attempts to find a registered handler for that data pattern. With a matching handler, it returns 200, otherwise 404.
It's working as designed, though I agree with you that it could be better documented.