-
Notifications
You must be signed in to change notification settings - Fork 152
Allowed HTTP Methods for Actions #10
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
Conversation
Limit actions to processing only requests with certain HTTP methods in a declarative way
>} | ||
|
||
|
||
To limit already existing Actions and get developers to know these new interfaces a temporary event listener will be added for controller_action_postdispatch event to log HTTP methods used with actions and then the full suite of functional tests (MTF and MFTF) would be ran to get information on as much actions as possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave logging in place to let extension developers know that they need to update their extensions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we discussed this, I just forgot to mention it - we can add a debug message each time an action without HTTP method declared s processed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with not having this if we going to have a mess detector rule.
> | ||
> if ($actionInstance instanceof $interface && $request->getMethod() !== $httpMethod) { | ||
> | ||
> throw new NotFoundException(__(‘Page not found.’)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember that we agreed to return 405 response code or no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we chose 404 because it's more consistent with what we do now and server must never return a 405 to GET and HEAD requests (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look at comments I left
Everybody's ok with adding a debug message each time an action without HTTP method restriction is found? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we guarantee that developers don't use just ActionInterface
? Instead of a specific one.
I'd suggest to include a static test (ideally, phpcs sniff) to the Work Breakdown.
|
||
Request method will be validated in the FrontController before executing a matched action, somewhat like this: | ||
|
||
>foreach ($interfaceMap as $interface => $httpMethod) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be necessary to iterate through all methods. You can do if (isset($interfaceMap[$request->getMethod()])
. If doesn't exist, the method is not supported by the application. If $actionInstance
does not implement the interface, also - an error.
The map will be opposite:
POST => HttpPostInterface
GET => HttpGetInterface
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll update that part
|
||
To limit already existing Actions and get developers to know these new interfaces a temporary event listener will be added for controller_action_postdispatch event to log HTTP methods used with actions and then the full suite of functional tests (MTF and MFTF) would be ran to get information on as much actions as possible. | ||
|
||
After corresponding Http*Method*ActionInterface will be added to every Action class we have information on. If an action is logged to be accessed only by GET methods it will allow only GET, if only by POST – allowing only POST etc. If by more than one methods – the Action class will not be updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If by more than one methods – the Action class will not be updated
Why not make it implement
multiple interfaces? Or if it's not clear why it really supports multiple methods, create a task to review it (as it can be a security issue).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we cannot be sure that an action actually expects multiple request methods or a test is invalid without investigation and if too many cases like that would be found it can take too match time to investigate them. I think I can write something like this: "If by more than one methods – the Action class will be updated to implement multiple interfaces or ignored." Would that be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Olga and would propose for now agree that we will need to review each case and discuss one more time if turns out that there are too many cases that need to be reviewed. Or you already know?
I think adding a rule to dev/tests/static/framework/Magento/CodeMessDetector/* that will detect classes implementing ActionInterface but not any HTTP method aware interfaces should be sufficient enough to alert developers about using these new interfaces |
validations algorithm, updating actions and static tests
I have updated the document to address the concerns |
It may be an overkill, if used in production mode. |
In the example, a |
Limit actions to processing only requests with certain HTTP methods in a declarative way