Skip to content

Requiring correct http methods on AdminController #7806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

mamazu
Copy link
Contributor

@mamazu mamazu commented Feb 12, 2025

Q A
Bug fix? no
New feature? no
BC breaks? technically yes
Deprecations? -
Fixed tickets -
Related issues/PRs -
License MIT
Documentation PR -

What's in this PR?

The metadata and the translations endpoints never accept any data so calling them with anything other than a get would not make sense. Let's also enforce that.

Why?

This makes it clear to the caller of the API that this endpoint only returns data.

In the long run those should be moved to their own controller classes.

@alexander-schranz
Copy link
Member

@mamazu do we need to keep HEAD or OPTIONS request in mind 🤔

@alexander-schranz alexander-schranz added the DX Affecting the end developer label Feb 20, 2025
@mamazu
Copy link
Contributor Author

mamazu commented Feb 20, 2025

I don't think the controller could handle them.

@alexander-schranz
Copy link
Member

alexander-schranz commented Feb 20, 2025

@mamazu nothing about the handling its more about HEAD, OPTION request should behave the same like currently, they should not return a 406 or other error code. Not sure if GET includes HEAD and OPTION requests.

@mamazu
Copy link
Contributor Author

mamazu commented Feb 20, 2025

@alexander-schranz I just checked it out, the HEAD request still works but the option request doesn't. However if I revert it back to "ANY" the OPTIONS request returns the the same contents as the GET which I don't think is how it's supposed to work.

@mamazu
Copy link
Contributor Author

mamazu commented Feb 20, 2025

Did some research. The option request should just return the header "Allow: OPTIONS, GET, ..." which this controller doesn't do. So sending an option request to this endpoint would be nonsense anyways.

@alexander-schranz
Copy link
Member

alexander-schranz commented Feb 20, 2025

As said its not about handling options request. More how this change could effect existing applications who maybe doing HEAD or OPTIONS request to our APIs.

@mamazu
Copy link
Contributor Author

mamazu commented Feb 20, 2025

Added OPTION as an allowed method again. HEAD requests work anyways (maybe some Symfony default handling)

Comment on lines 176 to 180
if ($request->getMethod() == Request::METHOD_OPTIONS) {
$response = new Response();
$response->headers->set('Allow', 'GET, OPTIONS, HEAD');
return $response;
}
Copy link
Member

@alexander-schranz alexander-schranz Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($request->getMethod() == Request::METHOD_OPTIONS) {
$response = new Response();
$response->headers->set('Allow', 'GET, OPTIONS, HEAD');
return $response;
}

Would not answer options request currently think that would be better handled in own bundle, via request listener.

@mamazu
Copy link
Contributor Author

mamazu commented Feb 20, 2025

Oops, that was code where I was just playing around. Removed it.

@alexander-schranz alexander-schranz merged commit c394051 into sulu:3.0 Feb 21, 2025
9 checks passed
@mamazu mamazu deleted the fixing_methods branch February 21, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants