The HTTP specification defines a short list of possible request methods:
GET
HEAD
POST
PUT
DELETE
CONNECT
OPTIONS
TRACE
PATCH
These request methods, also informally known as verbs, were intended to cover the gamut of client/server interactions.
At the same time, vanilla HTML links and forms can only make use of two of these: GET for links, and GET or POST for forms. This can be a problem, as a form submission may be a POST to create an entity, a PUT to update an entity, or a DELETE to remove one.
| Of course, in modern web applications, this is less important, as all the critical interactions will be driven from client-side code or via web sockets. |
Verb smuggling is a compromise; it allows ordinary HTML forms, but defines a query parameter that "smuggles" in the true request method. The api:method-param[ns=io.pedestal.http.route] interceptor extracts that query parameter value, converts it to a keyword, and updates the request-map.adoc :request-method key.
By default, the query parameter name is _method, but this can be configured
when invoking the method-param function.
The method-param interceptor only replaces the method of a POST request, and never with GET, HEAD, or OPTIONS;
in any other case, the query parameter is ignored, and the request keeps its method.
This keeps verb smuggling from defeating protection against cross-site request forgery (CSRF). The api:anti-forgery[ns=io.pedestal.http.csrf] interceptor requires a token for requests that may change state, but not for GET, HEAD, or OPTIONS requests, which are expected not to. Another site can make the user’s browser send a request to your application (a GET, from a link or an image, or a POST, from a form), but it can’t include the token. If the smuggled verb could turn such a GET into a DELETE, or such a POST into a GET, the request would pass the anti-forgery check as one method, and be routed as the other.
So a link can’t smuggle a verb; to reach a route for a method other than GET, use a form whose method is POST, such as one built from api:form-action-for-routes[ns=io.pedestal.http.route].
Can you improve this documentation? These fine people already did:
Howard M. Lewis Ship, Eric Dallo & Howard Lewis ShipEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |