Section 1.25

Confused deputy

Definition

A confused deputy is a program that holds authority of its own and is tricked by a less privileged requester into using that authority for the requester, on an object or operation that the requester itself is not allowed to use. Authority here means permission to perform an operation on an object, such as writing a file or signing a command. The deputy is confused because it applies its own authority to a request without checking whose authority should govern that request. Norm Hardy named the problem in 1988 [416].

The idea

Hardy described the case that gave the problem its name in “The Confused Deputy (or why capabilities might have been invented)” (1988). A compiler on a shared computer let each user name a file to receive part of the compiler’s output. The compiler also held permission to write a billing file in its own directory, where it recorded usage. A user named the billing file as the output file, and the compiler overwrote it. The operating system saw a write by the compiler to a file that the compiler may write, and allowed it. The compiler held its permission for two reasons, its own billing work and the user’s output, and nothing in the request said which reason applied.

The pattern recurs wherever one program acts for another. In cross-site request forgery (CSRF), a malicious web page makes the victim’s browser send a request to a site where the victim is logged in. The browser attaches the victim’s login cookie for that site, and the site carries out the request as the victim’s own. The browser is the deputy. In server-side request forgery (SSRF), a server that fetches a web address supplied by a user is given an address on the internal network, which only the server can reach. The server is the deputy.

The cases share ambient authority: authority that the system applies automatically to everything a program does, whatever the request names. The compiler’s permission to write its directory, the browser’s cookie and the server’s position inside the network are all ambient. The requester supplies only a name; the deputy supplies the authority.

How it works

Three roles take part.

The attack takes three steps.

  1. The requester names, in its request, an object that it may not use but the deputy may.

  2. The deputy checks something about the request, typically that the requester is logged in or that the request is well formed, but not whether the requester may perform this operation on this object.

  3. The deputy performs the operation with its own authority. The system that guards the object sees a request from the deputy, which is allowed, and grants it.

The root cause is that the request separates designation, which object is meant, from authority, the permission to act on it. The name travels from requester to deputy; the requester’s permission does not. Three repairs join the two again.

Worked example

A signing service S holds a private key. Its digital signature §5.14, a value that only this key can produce and that anyone holding the matching public key can check, is accepted by devices 17 and 42. Each device obeys a command only if it carries a valid signature by S over the command’s bytes. User U owns device 17 only. The service’s permission table has two rows for U: U may send reset to device 17, and U may send read to device 17.

The flawed service. U sends the request (device 42, reset). S checks U’s password, which is correct, and signs the bytes device=42 op=reset. U forwards the signed command to device 42 over any channel. Device 42 verifies the signature, which is valid because S really produced it, and resets. Every cryptographic step worked. S used its own authority, a key that device 42 accepts, for a request that only U’s authority should have governed, and U has no permission for device 42.

The repaired service. Before signing, S looks for the pair (device 42, reset) among U’s two rows. It is absent, so S refuses. The request (device 17, reset) is present, so S signs device=17 op=reset. Each device also checks that the device field inside the signed bytes names that device, so if U forwards this command to device 42, device 42 rejects it. Without the device field inside the signed bytes, a command signed for device 17 would be accepted by device 42 as well, since both devices accept the same key. Separate keys per device add least privilege: a part of S that serves only U’s devices would then hold no key that device 42 accepts.

Stated precisely

Call any party that holds permissions a principal: a user, a program or a device. Let Perm(p)\mathrm{Perm}(p) be the set of action-object pairs (a,o)(a, o) that principal pp may perform. A deputy DD serves a request in which principal uu asks for (a,o)(a, o). The deputy is confused when it performs (a,o)(a, o) for uu although (a,o)∈Perm(D)(a, o) \in \mathrm{Perm}(D) and (a,o)∉Perm(u)(a, o) \notin \mathrm{Perm}(u): its own authority, not the requester’s, made the request succeed. A deputy avoids confusion when, for every request it serves for uu, it performs (a,o)(a, o) only if (a,o)(a, o) lies in both Perm(u)\mathrm{Perm}(u) and Perm(D)\mathrm{Perm}(D).

The check must be bound to the action in three ways.

  1. Same requester: uu is authenticated, so the deputy knows whose permissions to consult.

  2. Same object: the oo that was checked is the oo that is acted on. A name that resolves to one object at the check and to another at the use, through a relative path, a symbolic link §13.10 or a change between the two moments, breaks this binding.

  3. Same operation: the bytes that the deputy signs or executes mean exactly the operation it checked, as read by the parser of whoever acts on them.

Limits and common mistakes

A confused deputy is an authorization §1.7 failure, not a cryptographic one. Signatures, encryption and key storage can all work correctly while the deputy misuses its authority.

Authentication §1.6 of the requester is not authorization of the request. Knowing who asked says nothing about whether that requester may use the named object.

Calling a component a relay, proxy or gateway does not reduce its authority. Whatever the component can reach with its own credentials, a requester may try to reach through it.

Recording the target in a log changes nothing about who could act on it. Only a check before the action, or a deputy that lacks the authority, prevents the misuse.

Capabilities help only if the deputy keeps them apart. A deputy that receives the requester’s capability, finds that it fails, and then retries with its own authority is confused again.

Questions answered

Can a relay ask a privileged verifier to authenticate the wrong device or object?

Yes: a relay can make a privileged verifier or signer vouch for the wrong device or object whenever that component chooses what to authenticate from fields the relay supplies, without checking that the party behind the relay may use that device, object and operation. This is the confused deputy problem: the privileged component applies its own authority, such as a signing key that many devices accept, to a request that only the requester’s authority should govern. For example, a signing service whose key devices 17 and 42 both accept receives, through a relay, a request from a user who owns only device 17 to sign “reset device 42”. If the service checks only that the user is logged in, it signs, and device 42 correctly verifies the signature and resets.

Four measures close the gap.

  1. Before using its authority, the privileged component checks the requester’s permission for the exact device or object and operation, and then signs or verifies exactly the object it checked.

  2. The authenticated bytes name the target device, the operation and a freshness value such as a counter, and each receiver checks that the target is itself.

  3. The signed bytes are the bytes the receiver will parse, so that the checked request and the executed request cannot be read differently.

  4. Keys are narrowed to what each part needs, for example one key per device or per customer, so that a confused component can affect only the objects its key reaches.

Related entries: Authorization (§1.7), Least privilege (§1.15), Authentication coverage (§5.41), Capability security (§1.40), Time-of-check to time-of-use (TOCTOU) (§9.26). Further reading: [416].