This should be my last post on Rohit Khare's
Decentralizing REST
thesis. I apologise to my readers for somewhat of a blogging glut around this
paper but there have been a number of topics I wanted to touch apon. This post
concerns the use of HTTP verbs for subscription and notification activities.
In section 5.1 Rohit describes the A+REST architectural style. It uses a
WATCH request and and NOTIFY response. By the time he reaches the R+REST and
ARREST styles of sections 5.2 and 5.3 he is using SUBSCRIBE requests and POST
responses. I feel that the jump to use POST (a standard HTTP request) is
unfortunate.
I think Rohit sees POST as the obvious choice here. The server wants to
return something to the client, therefore mutating the state of the client,
therefore POST is appropriate. rfc2616 has
this to say
about POST:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources;
- Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles;
- Providing a block of data, such as the result of submitting a
form, to a data-handling process;
- Extending a database through an append operation.
POST is often used outside of these kinds of context, especially as means of
tunnelling alternate protocols or architectural styles over HTTP. In this case
though, I think that its use is particularly aggregious. Consider this text
from
section 9.1.1
of rfc2616:
the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.
Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.
When the server issues a POST it should be acting on behalf of its user.
Who its user is is a little unclear at this point. There is the client owned
by some agency, the server owned by another, and finally the POST destination
possibly owned by an additional agency. If the server is acting on behalf of
its owner it should do so with extreme care and be absolutely sure it is
willing to take responsibilty for the actions taken in response to the POST.
It should provide its own credentials and act in a responsible manner,
operating in accordance with the policy its owner sets forward for it.
I see the use of POST in this way as a great security risk. If the server
generating POST requests is trusted by anybody then by using
POST as a notification it is transferring that trust to its client. Unless
client and server are owned by the same organisation or individual an
interagency conflict exists and an unjustified trust relationship is created.
Instead, the server must provide the client's credentials only or notify the
destination server in a non-accountable way. It is important that the server
not be seen to be requesting any of the sideeffects the client may generate
in response to the notification but instead that those sideeffects are
part of the intrinsic behaviour of the destination when provided with
trustworthy updates.
Ultimately I don't think it is possible or reasonable for a server to
present its client's credentials as its own. There is too much risk that
domain name or IP address records will be taken into account when processing
trust relationships. I think therefore that a new method is required, just as
is provided in the
GENA protocol
which introduces NOTIFY for the purpose.
It's not a dumb idea to use POST as a notification mechanism. I certainly
thought that way when I first came to this area.
Other examples
also exist. Rohit himself talks about the difficulty of introducing new methods
to the web and having to work around this problem in mod_pubsub using HTTP
headers. In the end though, I think that the introduction of subscription
to the web is something worthy of at least one new verb.
I'm still not sure whether an explicit SUBSCRIBE verb is required. Something
tells me that a subscribable resource will always be subscribed to anyway and
that GET is ultimately enough to setup a subscription if appropriate headers
are supplied. I'm still hoping I'll be able to do something in this area to
reach a standard approach.
The established use of GENA in
UPnP
may tip the cards. The fact that it exists and is widely deployed may outweigh
its lack of formal specification and standardisation. Its defects mostly appear
asthetic rather than fundamental, and it still may be possible to extend it
in a backwards-compatible way.
Benjamin