# Make sign-in requests tamper-proof

> Stop anyone handling the browser's address bar from reading or changing an app's sign-in request, and keep the code out of browser history.

In a plain sign-in, the app's request (its scopes, the API it wants, its return address) rides in the browser's
address bar. A browser extension, a proxy or a log can read it, and someone can alter it before it reaches the realm.
For a confidential app handling sensitive data, such as banking, health or administration, three tools close that gap,
and they work together. Users see nothing different.

| Tool | What it stops |
|---|---|
| **Pushed request** | The request never enters the browser; the browser carries only a one-time reference |
| **Signed request object** | The request is signed by the app; the realm ignores anything not under the signature |
| **Form post** | The code comes back as a form post, not in the address bar or browser history |

**Before you start:**

- **Who can do it:** a realm administrator, in a group that holds `RealmOwner`
  ([Delegated administration](/platform/realms/delegated-administration/)). `RealmViewer` can read the settings but
  not change them.
- **Where:** today this is done through the API; [Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`.
- **First:** the app is registered as a confidential client, and you have its public key.

## Lock the request down

<Steps>

1. Require pushed requests for the app:

   ```sh
   curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "requirePushedAuthorizationRequests": true }'
   ```

   To require them for every app in the realm, send the same field to
   `PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings`.

2. Let the app sign its requests:

   ```sh
   curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{
       "requestObjectSigningAlg": "ES256",
       "jwks": { "keys": [
         { "kty": "EC", "crv": "P-256", "kid": "app-key-1", "x": "…", "y": "…" }
       ] }
     }'
   ```

   `jwks` holds the app's **public** keys only; a private key is refused. Instead of `jwks`, the app may publish its
   keys at an `https` address given as `jwksUri`. Give one or the other, not both.

3. Have the app send `response_mode=form_post`. There's nothing to set: the realm answers with a page that posts the
   code to the registered return address.

</Steps>

## What the app does

- **Pushed:** the app's server posts the request to `https://foobar.cvyuh.com/oauth2/par`, authenticating as it does at
  the token endpoint. It gets a `request_uri` that works once, within a minute, and sends the browser to
  `/oauth2/authorize?client_id=…&request_uri=…`. A bad request is answered to the server and never shown in the
  browser.
- **Signed:** the app sends the request as a JWT signed with its registered key, in `request` (or inside the push). It
  must name the app as sender and the realm as receiver, and carry `nbf` and `exp` no more than an hour apart.
- **Encrypted:** the app may also encrypt the signed request to the realm's encryption key (the `use: enc` key in its
  key set, when the realm holds one), so the browser can't read it either. Set the client's
  `requestObjectEncryptionAlg` to `ECDH-ES`, and `requestObjectEncryptionEnc` if not `A128CBC-HS256`, the default. The
  signature is still checked once it is opened.

The realm never fetches a request from an address someone else names.

## Check it worked

Send the app's browser straight to `/oauth2/authorize` with its parameters in the address, and no `request_uri`. The
realm refuses it, since the app must push its requests.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The user sees an error page at sign-in | The app sent its request in the address bar, not pushed | Push it to `/oauth2/par` first |
| The push is refused `invalid_client` | The app's server didn't authenticate as it does at the token endpoint | Send its client credentials with the push |
| The `request_uri` is refused | It was used before, or a minute passed | Push again for each sign-in |
| The signed request is refused | Wrong key or algorithm, the realm or the app not named, or `nbf` and `exp` more than an hour apart | Sign with the registered key and `requestObjectSigningAlg` |

## Undo it

Set `requirePushedAuthorizationRequests` back to `false` on the client, or on the realm.

<Aside type="tip" title="The full high-security rules">
  For apps held to all of them at once, set one profile instead:
  [Hold a client to FAPI 2.0](../../services/fapi2-clients/).
</Aside>

## Related

- [Pushed authorization requests](../../../applications/client-security/pushed-authorization-requests/): the push, its
  lifetime and errors.
- [Signed request objects](../../../applications/client-security/request-objects/): signing and encryption.
- [Sign users in to a web app](../sign-in-web-app/): the sign-in this tightens.
