|
| 1 | +# Field-level encryption (secure storage) |
| 2 | + |
| 3 | +As part of our ongoing security and privacy work, the bot has an additional layer of protection for |
| 4 | +the most sensitive user data: field-level encryption. Selected database columns are encrypted at the |
| 5 | +application level, so sensitive fields stay protected even when someone has direct database access |
| 6 | +(for example, a technician reviewing a database for support or debugging). It is an extra safeguard |
| 7 | +layered on top of the broader security posture. |
| 8 | + |
| 9 | +## What it means for the open-source build |
| 10 | + |
| 11 | +In this repository the feature ships as a thin serialization wrapper with a passthrough crypto stub: |
| 12 | + |
| 13 | +- Self-hosted instances and the test suite run with no key and no configuration. Nothing to set up. |
| 14 | +- The registered columns are declared `TEXT`. The hooks serialize their JSON and integer values into |
| 15 | + that text on write and parse them back on read, so your model code keeps working with plain objects |
| 16 | + and numbers. |
| 17 | +- The actual encryption is injected only on the managed backend. You never need a key locally, and the |
| 18 | + encryption is a safe no-op here. |
| 19 | + |
| 20 | +The wrapper lives in `src/functions/secure-storage/`: |
| 21 | + |
| 22 | +- `fields.js` lists every protected column (the source of truth for what is secured). |
| 23 | +- `hooks.js` registers the serialization hooks on each model. |
| 24 | +- `fieldCrypto.js` is the passthrough stub the managed backend replaces. |
| 25 | + |
| 26 | +## Contributor rules |
| 27 | + |
| 28 | +If you write or change a module: |
| 29 | + |
| 30 | +- **Keep `TEXT` columns as `TEXT`.** The hooks serialize JSON and integers into them; changing the |
| 31 | + type breaks reads and writes. |
| 32 | +- **Adding a sensitive free-text or PII field?** Declare it `TEXT` and register it in |
| 33 | + `src/functions/secure-storage/fields.js` with its type (`string`, `json`, or `int`). Serialization |
| 34 | + then happens automatically and the encryption is a safe no-op locally. |
| 35 | +- **Do not register columns used in `WHERE`, `ORDER`, indexes, unique constraints, or aggregates.** |
| 36 | + Encrypting those would break lookups. IDs, foreign keys, enums, booleans, counters, timestamps, and |
| 37 | + external resource references stay as they are. |
| 38 | +- **You never need a key.** Encryption activates only on the managed backend. |
| 39 | + |
| 40 | +We update the existing fields of community modules when this requirement changes, so you normally do |
| 41 | +not have to touch anything unless you are adding a new sensitive field. |
0 commit comments