# One-time shares

> Send one version of a secret through a link that works once, optionally for one named user, before it expires.

A one-time share hands a secret to someone once, without giving them lasting access. You copy one version into a share
and get a link. The first user to read the link gets the values, and the share is gone. A link that leaks after it was
read, or after it expired, gives nothing.

Use it for a new starter's first password, or a value someone needs a single time. For access that lasts, give a
[grant](/secrets-store/sharing/grants/).

## Before you begin

- **Who:** anyone who may view the secret: its owner, someone with a `view` grant, or a nominee let in by
  [emergency access](/secrets-store/emergency-access/). The reader is any user signed in to the realm, or only the
  recipient you name. No privilege is needed.
- **Where:** the API. There are no screens yet.
- **First:** the store is on, and the version you share is live: not deleted or destroyed.

## How it works

The share is a copy of one version, sealed under a key that exists only in the link. The realm stores the sealed copy
and never the key, so without the link it can't open the share itself.

The reader, signed in to the realm, posts the link to the store. The link travels in the request body, never in an
address, so it doesn't land in the logs that proxies keep. A page that hands the link on should carry it after a `#`,
which a browser never sends to a server.

## Set it up

1. Make the share, as anyone who may view the secret. Here `maya` shares `web/github` with `ben`, for an hour
   ([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`):

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/share/web/github \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "ttl": 3600, "recipient": "ben" }'
   ```

   The realm answers `201`:

   ```json
   { "data": { "link": "<link>", "expires_at": "<RFC 3339 time>" } }
   ```

2. Send the link to the reader by any channel.

3. The reader, signed in as themselves, reads it once:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/shares \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "link": "<link>" }'
   ```

   The realm answers `200` with the values under `data.data`. Every later read answers `404`.

## What the reader sees

No message is sent; the reader has only the link you send them. Their first read answers the values; every read after
that answers `404`, for them and for anyone else.

**If the link answers `404` on its first read, someone else read it.** Unless it had expired, treat the value as
exposed: change the secret, and tell the person who sent it.

## When it fails

| Answer | When | What to do |
|---|---|---|
| `404` reading | The link was already read, has expired, is wrong, or names another recipient | If you hadn't read it and it hadn't expired, treat the value as exposed and change it; otherwise ask for a new share |
| `400` making, lifetime | `ttl` is `0` or longer than the realm allows | Send a `ttl` from 1 second up to the realm's `shareMaxTtl`, a week by default |
| `400` making, version | The version is deleted or destroyed | Share a live version |
| `404` making | The path, the version or the recipient isn't there, or you may not view a secret in a personal vault | Check the path and the recipient's user id |
| `403` making | You may not view the secret in a group's or the realm's vault, or hold only `use` | Ask for `view`, or ask someone who may view it |
| `400` reading, "no link provided" | The body has no `link` | Send `{ "link": "<link>" }` |
| `503` | The realm has no secrets key | See [Crypto-shredding](/secrets-store/keys-and-protection/crypto-shredding/) |

## Limits and defaults

| Limit | Default | Range | Set by |
|---|---|---|---|
| A share's lifetime | 600 seconds (ten minutes) | 1 second up to the realm's longest | `ttl` on the share; `shareDefaultTtl` for the realm |
| The longest a share may wait | 604800 seconds (a week) | 1 second to 30 days | `shareMaxTtl` in [Realm settings](/secrets-store/realm-settings/) |
| Reads per share | one | | |
| Withdrawing an unread share | not possible; it expires | | |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The recipient's first read answers `404` | Someone else read it first, or it expired | Check `expires_at`. If it hadn't expired, change the secret: the value is exposed |
| You sent a link to the wrong person | A share can't be withdrawn | Change the secret now, so the share holds a value that no longer works |
| The reader gets `404` though the link is fresh | The share names a different `recipient` | Make a new share for the right user |

## Audit record

Making a share is a `CREATED` record, and reading it a `DELETED` record under the reader. A share swept after it
expires writes no record. See [Secrets audit trail](/secrets-store/keys-and-protection/audit-trail/).

## Good to know

- **Read once.** Only one read gets the values, even if two arrive together.
- **It can't be withdrawn.** Once made, a share stays until it is read or expires. Keep `ttl` short.
- **A wrong link spends nothing.** A link with the right share but the wrong key reads nothing, and the share stays
  for the right link.
- **For one user, if you name one.** A share with a `recipient` opens for them alone. Anyone else finds nothing, and
  the share stays for the recipient.
- **A copy, not a pointer.** A later change to the secret doesn't reach the share.
- **Anyone who may view a secret may share it, with anyone in the realm.** The realm sets only how long shares last.
  See [What's next for sharing](/secrets-store/sharing/whats-next/#sharing-policy).

## Reference

| Field | What it sets |
|---|---|
| `version` | Which version to share. Leave it out for the latest |
| `ttl` | How many seconds the share waits to be read |
| `recipient` | The one user who may read it, by user id. Leave it out for anyone in the realm with the link |

## Related

- [Send a secret once](/secrets-store/guides/send-a-secret-once/): the task, start to finish.
- [Realm settings](/secrets-store/realm-settings/): the default and longest lifetimes.
- [Grants](/secrets-store/sharing/grants/): access that lasts.
