This specification extends the OAuth signature to include integrity checks on HTTP request bodies with content types other than application/x-www-form-urlencoded.
Notation and Conventions
3. The oauth_body_hash Parameter
3.1. Hash Algorithm
3.2. Signing the Request
3.3. Verifying the Request
5. Security Considerations
Appendix A. Obtaining the HTTP Entity Body
Appendix B. Unkeyed vs Keyed Hash Algorithms
§ Author's Address
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119] (Bradner, B., “Key words for use in RFCs to Indicate Requirement Levels,” .).
Unless otherwise noted, this specification is written as a direct continuation of [OAuth Core 1.0] (OAuth Core Workgroup, “OAuth Core 1.0,” .), inheriting the definitions and guidelines set by it.
The OAuth Core specification [OAuth Core 1.0] (OAuth Core Workgroup, “OAuth Core 1.0,” .) provides body integrity checking only for application/x-www-form-urlencoded request bodies. Other types of request bodies are left unsigned. An eavesdropper or man-in-the-middle who captures a signed request URL may be able to forward or replay that URL with a different HTTP request body. Nonce checking and the use of https can mitigate this risk, but may not be available or effective in some environments.
This specification describes a method to provide an integrity check on the request body without requiring signatures of arbitrary byte streams. An unkeyed hash of the request body is taken, the resulting hash value is added to the list of OAuth parameters, and the normal OAuth signature base string is signed.
This extension is forward compatible: Service Providers that have not implemented this extension can verify requests sent by Consumers that have implemented this extension. If the Service Provider implements this specification the integrity of the body is guaranteed. If the Service Provider does not check body signatures, the remainder of the request will still validate using the OAuth Core signature algorithm.
This specification is only useful when cryptographic signatures are used. The OAuth PLAINTEXT signature algorithm does not provide integrity checks for any portion of the request.
The body hash parameter MUST NOT be sent on requests that use the application/x-www-form-urlencoded content-type. The body hash parameter MUST NOT be sent on HTTP GET or HEAD requests. The body hash parameter SHOULD be sent on all other requests.
The body hash algorithm is determined by the OAuth signature method used.
New OAuth signature methods SHOULD specify the hash algorithm used to generate the body hash.
To sign a request, the OAuth Consumer MUST:
Service Providers verify the integrity of request bodies by verifying the OAuth signature as described in [OAuth Core 1.0] (OAuth Core Workgroup, “OAuth Core 1.0,” .). and also verifying the value of the oauth_body_hash OAuth protocol parameter.
To summarize, Service Providers may encounter any of the following situations:
Sample HTTP request:
PUT /resource HTTP/1.1 Host: www.example.com Content-Type: text/plain Content-Length: 12 Hello World!
Base64 encoded SHA-1 hash of the body:
Signature Base String (with some line breaks added for readability):
PUT&http%3A%2F%2Fwww.example.com%2Fresource&oauth_body_hash%3D Lve95gjOVATpfV8EL5X4nxwjKHE%253D%26oauth_consumer_key%3Dconsum er%26oauth_nonce%3D10369470270925%26oauth_signature_method%3DH MAC-SHA1%26oauth_timestamp%3D1236874236%26oauth_version%3D1.0
Signed request with body hash (with some line breaks added for readability):
PUT /resource HTTP/1.1 Host: www.example.com Authorization: OAuth realm="http%3A%2F%2Fwww.example.com", oauth_body_hash="Lve95gjOVATpfV8EL5X4nxwjKHE%3D", oauth_consumer_key="consumer", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1236874155", oauth_nonce="10288510250934", oauth_version="1.0", oauth_signature="08bUFF%2Fjmp59mWB7cSgCYBUpJ0U%3D" Content-Type: text/plain Content-Length: 12 Hello World!
Many factors besides the bytes of the request body can influence the interpretation of the body of the HTTP request. For example, a content-type or content-encoding header can change the way a server handles an HTTP request. This specification does not include an integrity check on the HTTP request headers. OAuth deployments whose security could be impacted by an attacker who tampers with HTTP request headers should use other mechanisms (such as HTTPS) to protect the confidentiality and integrity of the entire HTTP request.
Not all programming platforms provide an easy mechanism to obtain the raw octets of the HTTP entity body. Reading the entity body as raw octets may have side effects, such as inhibiting automatic character set conversion. Transfer-encodings such as gzip also complicate implementation. On the other hand, reading the entity body as text may perform lossy conversions that prevent recovery of the original octet stream in some situtations. Character set conversions are not always one-to-one mappings, so solutions that rely on converting text back to the original octet stream are likely to fail in environments with multibyte characters.
All of these factors, and others, can make it difficult to drop in a "verify-the-signature" filtering layer prior to other request processing. The verification layer must consider the assumptions of downstream processing code on the state of the request body.
Implementers of this specification should be aware of these difficulties and consider the best way to address them in their programming frameworks.
This specification deliberately uses an unkeyed hash algorithm (SHA-1) to provide an integrity check on the body instead of a keyed hash algorithm such as HMAC-SHA1. This decision was made because signing arbitrary octet streams is poor cryptographic hygiene. It can lead to unexpected problems with cryptographic protocols.
For example, consider a proxy that uses OAuth to add authentication information to requests sent by an untrusted third-party. If the proxy signs arbitrary octet streams, the third-party can use the proxy as an oracle to forge authentication messages.
Including the result of an unkeyed hash in the normal signature base string allows the proxy to add an integrity check on the original message without creating a signing oracle.
|[OAuth Core 1.0]||OAuth Core Workgroup, “OAuth Core 1.0.”|
|[RFC2045]||Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies,” RFC 2045.|
|[RFC2119]||Bradner, B., “Key words for use in RFCs to Indicate Requirement Levels,” RFC 2119.|
|[RFC2616]||Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, “Hypertext Transfer Protocol -- HTTP/1.1,” RFC 2616.|
|[RFC3174]||Eastlake, 3rd, D. and P. Jones, “US Secure Hash Algorithm 1 (SHA1),” RFC 3174.|