# Secrets

> What the secret field guarantees, how a secret reaches the owner's server, and what it cannot do.

A step may need a key, a token or a sign-in code. It is typed in `<alta-secret-field>`, and only there: no other
element of the library makes a password field, and a test of the repository checks it.

## What the field guarantees

| Guarantee | How |
|---|---|
| A password field, not remembered | the element makes the input itself: `type="password"`, `autocomplete="off"`, no `name`, ignored by password managers' autofill; never in a `<form>` with an action |
| The page cannot read it | a closed shadow root; the element has no `value`; its events say only `{ filled, lengthOk }` |
| It goes only to the owner's server | the client takes the field, not a string: `agree(planId, { secretsFrom: { key: field } })`. The value is read and the field cleared in the same tick, then put in the JSON body of that one request |
| Same origin, safe transport | the client refuses to send it to another origin, or over plain HTTP off `localhost`: error `secret-origin`, nothing sent |
| Never in a URL, a log, a save | not in a header, not in the plan request; the flows' states and errors have no place that can hold it |
| Cleared | after it is sent, on cancel, when the element leaves the page, and after 10 minutes untouched |

On the server, the value goes to the program on its standard input, or to the program's own secret store, never in its
arguments. It is never written to the run's journal, never echoed back to the page.

## Using it

The forms of the library compose the field: `<alta-values-form>` for an executor's secret argument, `<alta-signin>`
for the `secret` sign-in and the code of a link sign-in. Their agreement sends the field. On your own markup:

```html
<alta-secret-field label="Your bot's token"></alta-secret-field>
```

```js
const field = document.querySelector("alta-secret-field");
await client.agree(plan.planId, { executor: plan.executor, secretsFrom: { telegram_token: field } });
```

## What it cannot do

- It does not protect against a hostile script running in the same page. The page is the owner's own, served by their
  server under a content policy of `script-src 'self'`.
- A `fetch` given to `createAltaClient` (the seam tests use) sees the body. That is why it is an argument, never a
  global.
- A tool's own sign-in (its Terminal window, its browser page) stays offered next to the field.
