Macaroons 101: Contextual Confinement – Elegant Authorization
So you have a list of constraints: c1, c2, c3. You have a secret key on your server, &#x27;k&#x27;. You calculate the signature as &#x27;HMAC( HMAC( HMAC(k, c1), c2) c3)&#x27;.<p>So anyone can add constraints and then create a new valid signature by HMAC&#x27;ing the additional constraint into the existing signature, right? You can add constraints, but of course, you can&#x27;t remove them later if you only have the latest iteration of the signature.<p>I&#x27;m trying to see the use-case here... is it a 3rd party taking one of these signed strings in order to append their own &quot;constraints&quot; onto it, cycle the signature, pass it to an end-user, who will then hand it back to your server? And even if this happened, how would you know at the end of the day who actually added the constraint? All but the first HMAC can be done by <i>anyone</i>, so aren&#x27;t you just creating work for yourself?<p>Specifically how is this ever better than just doing a single HMAC(key, data) on everything that you control, specifying some delimiter character to know where your own signed data ends, and then everything else is just unsigned? I guess if you trust your link to the 3rd party, and if you trust they will add the proper constraints, then the only benefit is you know once constraints are added they cannot be removed without access to the original signature.<p>Going directly to the paper, they show an example on Page 4 (<a href="http:&#x2F;&#x2F;imgur.com&#x2F;ARJNdu6" rel="nofollow">http:&#x2F;&#x2F;imgur.com&#x2F;ARJNdu6</a>) of a 3rd party service adding additional constraints onto an existing set;<p><pre><code>  For example, Figure 4 shows a macaroon authorizing a user at client C to
  access chunk 235 at a key-value storage service TS. This macaroon has
  been derived as a strict attenuation of another, more permissive macaroon
  —held by the social-networking “forum service” FS—by both eliding that
  macaroon’s signature (called, say KFS), and by adding caveats whose 
  predicates require a specific chunk and client IP address to be present
  in the request context. Even so, this macaroon’s signature, KUSER, both
  allows the target storage service to verify its integrity, and also
  allows its bearer to derive new, further attenuated macaroons. In this
  manner, macaroon signatures both protect integrity and act as keys.
</code></pre>
&quot;Integrity&quot; usually means you know something was not altered, so I think it&#x27;s a bit dangerous to call it that. The coloring of the figure is also misleading. With the proposed nested HMAC construction, we do not actually know which caveats were added by TS versus which were added by FS, or perhaps Mallory. All that &#x27;TS&#x27; knows is that these constraints exist, it loses a key piece of information, namely, the ability to prove which of the constraints are guaranteed to be first-party constraints, versus which were added later by third parties. For example, this could expose &#x27;TS&#x27; to potential DoS attacks because anyone can add potentially expensive-to-verify &quot;first-party&quot; constraints which the server could be tricked into thinking that it had actually added itself.<p>Instead, the server should HMAC the full set of its own constraints with its own key, and then a single delimiter should be added. If third-parties want to add additional sets of constraints, then the nested HMAC can start being used, but again I would propose, first, sets of constraints be added atomically with some delimiter to reduce the number of wasted HMAC cycles, and second, there should be a way to include an additional shared secret between TS and FS in the HMAC process so that TS can actually validate who added the constraints without significantly increasing the size of the payload.<p>Edit: So, what I get out of this after ~30 minutes of review is it&#x27;s a very high level protocol for how an already trusted set of servers might go about letting each other specify constraints. Frankly, I&#x27;m not sure why that&#x27;s 16 pages of research. I think the HMAC chain implies more security than you actually get, and actually involves a subtle trade-off that I don&#x27;t see addressed anywhere in the paper (but I didn&#x27;t read it <i>thoroughly</i>)