Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Add the docs/soc2 pack, and audit account closures and deletions
Clauded1299eb6e9fe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2de5b3b..607d788 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -43,6 +43,12 @@ release says when it does.`docs/backup-and-restore.md`. `vercel.json` has a second daily cron job,which does nothing until the token is set.+- Account closure requests and account deletions are recorded in the site+ audit trail.+- `docs/soc2`: a SOC 2 pack for organizations that put an install in their+ audit: a control map to the Trust Services Criteria, vendor duties,+ questionnaire answers and sample policies.+### Project security- CodeQL, dependency review, a weekly `npm audit` and OpenSSF Scorecard rundiff --git a/docs/part11/known-gaps.md b/docs/part11/known-gaps.mdindex 7343dbf..c6582c2 100644--- a/docs/part11/known-gaps.md+++ b/docs/part11/known-gaps.md@@ -8,7 +8,6 @@ What Part 11 mode does not do yet, and what to do instead. These are also listed| **No biometrics or passkeys.** Signing uses email and password. | 11.200(b) | Not needed: email and password meet 11.200(a). || **No signature meaning on templates.** A draft made from a template needs a meaning chosen for each signer before it can be sent. | none | The send is refused until each meaning is chosen, so nothing goes out without one. || **Full database access can rewrite the audit chain** consistently. | 11.10(e) | Limit database access, and file audit exports outside the database (SOP-5). |-| **No built-in backup of the PDFs** in Vercel Blob. | 11.10(c) | Copy the Blob store on a schedule, and test a restore (SOP-5). || **Signers outside your organization** need an account on your install, and an administrator must confirm who they are. | 11.100 | Fine for staff. For outside parties, decide whether this is workable or keep those records out of Part 11 mode. |Suggestions and fixes are welcome on the project's GitHub.diff --git a/docs/part11/procedures.md b/docs/part11/procedures.mdindex d18870a..09db5cf 100644--- a/docs/part11/procedures.md+++ b/docs/part11/procedures.md@@ -47,7 +47,7 @@ Short templates for the procedures Part 11 expects you to have. Put each into yo2. For each finished regulated record, the sender files the signed PDF, the certificate and the envelope's audit trail CSV in `[the record system]` within `[N]` days.3. If a chain check ever shows broken, stop using the install for new records and handle it as an incident.4. Records are kept for `[the period your predicate rules require]`. They are deleted only by hand, under `[procedure]`, after that period, with the deletion recorded.-5. Backups of the database and of the Blob store are taken `[how and how often]` and a restore is tested `[how often]`.+5. Backups of the database and of the Blob store are taken `[daily, by the built-in backup (docs/backup-and-restore.md), or how]` and a restore is tested `[how often]`.## SOP-6 Incidentsdiff --git a/docs/part11/risk-assessment.md b/docs/part11/risk-assessment.mdindex ca95d85..5f2eb71 100644--- a/docs/part11/risk-assessment.md+++ b/docs/part11/risk-assessment.md@@ -7,20 +7,20 @@ A starting risk assessment for SignuDoc in Part 11 mode. Score each risk for you**Detectability** (D): 1 = would certainly be found, 5 = would probably not be found.A risk priority (S × L × D) of 27 or more needs a further control or a documented acceptance.-| # | Risk | Controls in SignuDoc | Controls you add | S | L | D | RPN |-| --- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | --- | --- | --- | --- |-| R1 | Someone signs as another person. | Own account and password at open and at signing. An admin confirms identity. Lock after 5 wrong passwords, with admin alert. | Identity check procedure, no shared passwords, training. Investigate every lock. | 5 | 1 | 3 | 15 |-| R2 | A signer's identity confirmation is wrong. | Admin must record how they checked. The confirmation is in the install audit trail. | Two-person check for identity confirmation. Periodic review of confirmed accounts. | 5 | 2 | 3 | 30 |-| R3 | A record is changed after signing. | Sealed PDF. The verify page checks a copy against the stored hash. | Keep the signed PDF with the record. Check copies on the verify page when in doubt. | 5 | 1 | 1 | 5 |-| R4 | An audit trail entry is changed or deleted in the database. | Hash chain over every entry, checked on screen and in every CSV export. | Restrict database access to named people. Export and file audit trails at each review. | 5 | 1 | 2 | 10 |-| R5 | A database administrator rewrites the whole chain consistently. | None: someone with full database access can recompute hashes. | Keep exported CSVs outside the database (they carry the hashes at that time). Limit and log Neon console access. | 5 | 1 | 4 | 20 |-| R6 | A record is deleted early. | Part 11 records are skipped by the retention timer and by data requests. A retention period can't be set in Part 11 mode. | Back up the database and storage. Control who can close accounts or delete by hand. | 5 | 1 | 3 | 15 |-| R7 | Records are lost when a service fails or an account lapses. | None in the software. | Neon backups or point-in-time restore, a Blob copy, and supplier review ([Suppliers](suppliers.md)). Keep billing current. | 5 | 2 | 2 | 20 |-| R8 | Part 11 mode is turned off by mistake. | Admin only, recorded in the install audit trail. Records already sent keep their rules. | Audit review procedure checks for `part11_mode_changed`. | 3 | 2 | 2 | 12 |-| R9 | The signature meaning is wrong for the record. | The sender chooses it, and the signer sees and confirms it before signing. | Procedure says which meaning each record type needs. | 3 | 2 | 3 | 18 |-| R10 | A session left open is used by someone else. | Each signature needs the password again. An administrator can end sessions after a time without use and cap their length (Settings, Organization, Sign-in security). | Set an idle timeout. Lock screens when away, by policy. | 3 | 2 | 3 | 18 |-| R11 | A new SignuDoc version breaks a control. | Automated tests on every change, including a Part 11 browser test. | Change control: review, re-run the OQ for changed areas, approve before use. | 5 | 2 | 2 | 20 |-| R12 | Clock error makes times wrong. | Times come from the server (Vercel) and are written in UTC. | Note the time source in the IQ. | 3 | 1 | 3 | 9 |-| R13 | Emails (invitations, lock alerts) don't arrive. | Delivery is tracked, and the Email panel shows a failing address. | Check the Email panel in the IQ. Admins check People for locks during audit review. | 2 | 2 | 2 | 8 |+| # | Risk | Controls in SignuDoc | Controls you add | S | L | D | RPN |+| --- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | --- | --- | --- | --- |+| R1 | Someone signs as another person. | Own account and password at open and at signing. An admin confirms identity. Lock after 5 wrong passwords, with admin alert. | Identity check procedure, no shared passwords, training. Investigate every lock. | 5 | 1 | 3 | 15 |+| R2 | A signer's identity confirmation is wrong. | Admin must record how they checked. The confirmation is in the install audit trail. | Two-person check for identity confirmation. Periodic review of confirmed accounts. | 5 | 2 | 3 | 30 |+| R3 | A record is changed after signing. | Sealed PDF. The verify page checks a copy against the stored hash. | Keep the signed PDF with the record. Check copies on the verify page when in doubt. | 5 | 1 | 1 | 5 |+| R4 | An audit trail entry is changed or deleted in the database. | Hash chain over every entry, checked on screen and in every CSV export. | Restrict database access to named people. Export and file audit trails at each review. | 5 | 1 | 2 | 10 |+| R5 | A database administrator rewrites the whole chain consistently. | None: someone with full database access can recompute hashes. | Keep exported CSVs outside the database (they carry the hashes at that time). Limit and log Neon console access. | 5 | 1 | 4 | 20 |+| R6 | A record is deleted early. | Part 11 records are skipped by the retention timer and by data requests. A retention period can't be set in Part 11 mode. | Back up the database and storage. Control who can close accounts or delete by hand. | 5 | 1 | 3 | 15 |+| R7 | Records are lost when a service fails or an account lapses. | An optional daily backup of the database and files to a second Blob store ([Backup and restore](../backup-and-restore.md)). | Turn the backup on, keep its store in another Vercel team, test a restore, and review suppliers ([Suppliers](suppliers.md)). Keep billing current. | 5 | 2 | 2 | 20 |+| R8 | Part 11 mode is turned off by mistake. | Admin only, recorded in the install audit trail. Records already sent keep their rules. | Audit review procedure checks for `part11_mode_changed`. | 3 | 2 | 2 | 12 |+| R9 | The signature meaning is wrong for the record. | The sender chooses it, and the signer sees and confirms it before signing. | Procedure says which meaning each record type needs. | 3 | 2 | 3 | 18 |+| R10 | A session left open is used by someone else. | Each signature needs the password again. An administrator can end sessions after a time without use and cap their length (Settings, Organization, Sign-in security). | Set an idle timeout. Lock screens when away, by policy. | 3 | 2 | 3 | 18 |+| R11 | A new SignuDoc version breaks a control. | Automated tests on every change, including a Part 11 browser test. | Change control: review, re-run the OQ for changed areas, approve before use. | 5 | 2 | 2 | 20 |+| R12 | Clock error makes times wrong. | Times come from the server (Vercel) and are written in UTC. | Note the time source in the IQ. | 3 | 1 | 3 | 9 |+| R13 | Emails (invitations, lock alerts) don't arrive. | Delivery is tracked, and the Email panel shows a failing address. | Check the Email panel in the IQ. Admins check People for locks during audit review. | 2 | 2 | 2 | 8 |Reviewed by `[name, role]`, approved by `[name, role]`, on `[date]`.diff --git a/docs/soc2/README.md b/docs/soc2/README.mdnew file mode 100644index 0000000..4233396--- /dev/null+++ b/docs/soc2/README.md@@ -0,0 +1,38 @@+# SOC 2 pack++SOC 2 is an audit of an **organization**, not of software. Nobody can certify SignuDoc as "SOC 2 compliant", because SignuDoc is code that each organization deploys and runs for itself. What an auditor looks at is your organization: how you run the install, who can reach it, how you change it, and which vendors you rely on.++This folder is there to make that easy. It is for the person at a deploying organization who has to put a SignuDoc install into their SOC 2 scope, or answer a customer's security questionnaire about it.++| File | What it is for |+| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |+| [Control map](control-map.md) | The SOC 2 Trust Services Criteria, and for each one what the app does, what the vendors do, and what is yours to do. |+| [Vendor duties](vendor-duties.md) | The services an install runs on, what each holds, which reports to collect, and the complementary controls their reports expect. |+| [Questionnaire answers](questionnaire.md) | Answers to the questions security questionnaires ask most, for an install set up as this pack recommends. Edit them to match yours. |+| [Sample policies](policies/) | Short starting points for the policies an auditor asks to see, written for a SignuDoc install. Adopt them into your own policy set. |+| [Setup checklist](#setup-checklist) | The settings that make the answers above true. |++The pack describes SignuDoc as of the release it ships with. Check it against the version you run, and against your vendors' current reports: what they offer changes, and so does what your plan includes.++## Who does what++- **SignuDoc (the code)** gives you the controls inside the app: sign-in security, roles, audit trails, sealed documents, retention, backups. It is open source and provided as is, with no supplier agreement. You review and accept each release.+- **Your vendors** (Vercel, Neon, Resend, and any optional ones) run the infrastructure. Each has its own SOC 2 report, and your auditor treats them as subservice organizations, usually by the carve-out method: you collect their reports and show you meet the complementary user entity controls they list.+- **Your organization** owns everything else: who gets access, how changes are approved, monitoring, incident response, vendor review, policies, and training.++## Setup checklist++Turn these on before an audit period starts. Each links to how.++- [ ] Vercel team on a plan that includes the SOC 2 report and the controls you need (see [Vendor duties](vendor-duties.md)). Team members limited to the people who run the install, each with their own login and MFA.+- [ ] Neon project on a plan whose restore window meets your recovery objective. Console access limited the same way.+- [ ] `CRON_SECRET` set, so only Vercel's cron can start the daily jobs ([self-hosting](../self-hosting.md#daily-cleanup)).+- [ ] `SETUP_TOKEN` set before the install's URL is public, or setup finished at once ([self-hosting](../self-hosting.md#lock-down-a-new-install)).+- [ ] Single sign-on through your identity provider, with `PASSWORD_SIGN_IN=off` and one or two break-glass addresses ([self-hosting](../self-hosting.md#single-sign-on)). Or, without SSO, two-step sign-in required for everyone (Settings, Organization, Sign-in security).+- [ ] Session limits set: for example 30 minutes without use and 12 hours at most (Settings, Organization, Sign-in security).+- [ ] Sign-up limited to your own email domains, or closed (Settings, Organization).+- [ ] A Vercel log drain to your SIEM, with alerts on `sign_in_locked`, `role_changed`, `two_factor_requirement_changed`, `settings_changed`, `backup_failure` and `retention_job_failure` ([self-hosting](../self-hosting.md#send-the-audit-trail-to-your-siem)).+- [ ] The daily backup to a second Blob store in another Vercel team, and a test restore on the calendar ([Backup and restore](../backup-and-restore.md)).+- [ ] Retention rules that match your records policy (Settings, Organization).+- [ ] The GitHub repository that deploys the install (your copy) with branch protection on the production branch, and updates taken through pull requests ([self-hosting](../self-hosting.md#keep-your-install-up-to-date)).+- [ ] A support address that reaches a monitored mailbox (Settings, Organization).diff --git a/docs/soc2/control-map.md b/docs/soc2/control-map.mdnew file mode 100644index 0000000..c82e546--- /dev/null+++ b/docs/soc2/control-map.md@@ -0,0 +1,112 @@+# Control map++The SOC 2 Trust Services Criteria (2017, revised points of focus 2022), and for each one what a SignuDoc install gives you, what your vendors give you, and what is left for your organization. "Yours" items are where an auditor will ask for your own evidence.++Most SignuDoc installs put **Security** (the common criteria, CC) in scope, and often **Availability** and **Confidentiality**. **Processing Integrity** and **Privacy** are covered at the end.++Where a row says "evidence", it names what you can show an auditor.++## CC1 Control environment++| Criterion | SignuDoc | Vendors | Yours |+| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |+| CC1.1 to CC1.5 Integrity, oversight, structure, competence, accountability | Nothing in the software. Roles in the app (administrator, member) are listed under People. | Their own, in their reports. | Your org chart, code of conduct, background checks, security training, and named owners for the install (a system owner and at least two administrators). |++## CC2 Communication and information++| Criterion | SignuDoc | Vendors | Yours |+| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |+| CC2.1 Quality information | Two hash-chained audit trails: one per document, and one for the install (sign-ins, settings, roles, account changes). Both download as CSV, and copy to your SIEM as JSON. | | Decide who reviews them and how often ([monitoring policy](policies/logging-and-monitoring.md)). |+| CC2.2 Internal communication | The support address set at setup is shown to every user and signer. | | Tell staff how to report a security concern. Keep this pack and your policies where staff can read them. |+| CC2.3 External communication | Terms and privacy links (Settings, Organization), shown on sign-in, sign-up and signing pages. Signers see who sent a document and the support address. | | Your published terms, privacy notice and security contact. Notify customers of incidents per your contracts. |++## CC3 Risk assessment++| Criterion | SignuDoc | Vendors | Yours |+| ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |+| CC3.1 to CC3.4 Risk identification, fraud, change | A worked risk assessment for the app is in [docs/part11/risk-assessment.md](../part11/risk-assessment.md), usable outside Part 11. | | Your own risk register, with the install in it, reviewed at least yearly and when you take a release with security changes (see the changelog). |++## CC4 Monitoring activities++| Criterion | SignuDoc | Vendors | Yours |+| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |+| CC4.1 Ongoing and separate evaluations | Chain checks on both audit trails (Settings, Organization, Sign-in security; each document's audit page). | Vercel, Neon and Resend reports cover their own monitoring. | A periodic access review and audit-trail review. A yearly penetration test of your install, if your customers ask for one. |+| CC4.2 Communicating deficiencies | Security fixes are listed in the changelog and release notes. Vulnerabilities are reported privately ([SECURITY.md](../../SECURITY.md)). | | Watch the SignuDoc repository's releases (GitHub, Watch, Custom, Releases). Track findings to closure. |++## CC5 Control activities++| Criterion | SignuDoc | Vendors | Yours |+| ---------------------------------------------- | ----------------------------------------------------------------- | ------- | ------------------------------------------------------------------ |+| CC5.1 to CC5.3 Selection, technology, policies | The settings in the [setup checklist](README.md#setup-checklist). | | Adopt the [sample policies](policies/) and show they are followed. |++## CC6 Logical and physical access++| Criterion | SignuDoc | Vendors | Yours |+| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| CC6.1 Access security software and architecture | Single sign-on over OIDC with password sign-in off, or passwords of 15+ characters checked against breach lists, with two-step sign-in (authenticator app) that an administrator can require. Two roles: administrator and member. Members see only their own documents. Signers reach one document through a single-use link and an optional emailed or access code. Private Blob store: every file is read through the app. | Vercel: TLS, isolation of functions, private Blob storage. Neon: encryption at rest, TLS-only connections. | Who is on the Vercel team, the Neon project, the Resend account and the GitHub repository, each with MFA. Evidence: member lists. |+| CC6.2 Registering and authorizing users | Sign-up limited to listed domains, or closed. With SSO, new people get an account at first sign-in under the same rule. Administrators make or remove other administrators under People; each change is in the site audit trail (`role_changed`). | | Your joiner process. With SSO, assignment to the app in your identity provider is the approval. Evidence: provider assignment log, or a ticket per new administrator. |+| CC6.3 Removing access | With SSO, someone removed in your identity provider cannot sign in again; their open session ends at the session limit you set. Administrators can sign someone out everywhere by resetting their two-step sign-in. Account closures and deletions are in the site audit trail. | | Your leaver process, including the vendor consoles. Evidence: identity provider deprovisioning log, access review. |+| CC6.4 Physical access | Not applicable (no hardware). | Carved out to Vercel's and Neon's cloud providers. | Collect their reports. |+| CC6.5 Disposal | Retention rules delete finished documents and their files after the period you set. Closed accounts are deleted after their export window. The daily backup drops copies of deleted files after `BACKUP_KEEP_DAYS`. | Vercel and Neon media disposal, in their reports. | Your retention schedule ([data retention policy](policies/data-retention.md)). |+| CC6.6 Threats from outside | HTTPS only (HSTS), a strict Content Security Policy, no framing, rate limits on sign-in, sign-up, signing and uploads, a lockout after ten wrong passwords, optional Vercel BotID, and signing links that are random and single-purpose. | Vercel's edge network and firewall (DDoS mitigation). | Vercel Firewall rules if you need more (IP allow lists are a paid Vercel feature). |+| CC6.7 Data in transit | Every page and API is HTTPS. Database connections need TLS. | Vercel TLS termination. Neon TLS. Resend TLS to receiving servers where they support it. | Your own sending domain with SPF and DKIM (Settings, Organization, Email). |+| CC6.8 Malicious software | Uploads must be unencrypted PDFs of 20 MB or less, and are checked as such. The app runs no uploaded code. Dependencies are checked by CodeQL, dependency review and `npm audit` in the SignuDoc repository. | Vercel's build isolation. | Endpoint protection on the computers your staff use. |++## CC7 System operations++| Criterion | SignuDoc | Vendors | Yours |+| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |+| CC7.1 Detecting vulnerabilities and changes | Each release lists its security fixes. Releases carry an SBOM and signed provenance ([SECURITY.md](../../SECURITY.md)). | Vercel and Neon patch their platforms. | Take SignuDoc releases (the update workflow opens a pull request each week). Check the SBOM against your vulnerability feed if you have one. |+| CC7.2 Monitoring for anomalies | Every audit row and security event goes to the function logs as a JSON line; a log drain sends them to your SIEM. Sign-in failures carry the reason and IP address. Lockouts are their own event. | Vercel log drains (paid plans). | Alerts in your SIEM ([monitoring policy](policies/logging-and-monitoring.md)). Evidence: alert rules, and tickets from alerts. |+| CC7.3 to CC7.5 Evaluating, responding to and recovering from incidents | Sign out everywhere; reset someone's two-step sign-in; signing locks; void a document; chain checks show tampering; restore from backup. | Vendors notify you of their incidents per their terms. | An incident response plan and its tests ([incident response policy](policies/incident-response.md)). |++## CC8 Change management++| Criterion | SignuDoc | Vendors | Yours |+| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| CC8.1 Changes to the system | Each SignuDoc release is tested in CI (typecheck, lint, unit tests, Postgres tests, an end-to-end browser test) and described in the changelog. The update workflow brings a release into your copy as a pull request, with a Vercel preview. Database changes run in the production build. Settings changes are in the site audit trail. | Vercel keeps every deployment and can roll back to one. | Branch protection on your copy's production branch, a reviewer for each update pull request, and a record of who approved it ([change management policy](policies/change-management.md)). Evidence: merged pull requests. |++## CC9 Risk mitigation++| Criterion | SignuDoc | Vendors | Yours |+| -------------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |+| CC9.1 Business disruption | Daily backup to a second Blob store, and a scripted restore ([backup and restore](../backup-and-restore.md)). | Neon point-in-time restore on your plan. | Recovery objectives, a tested restore, and continuity of the people who can run it ([backup policy](policies/backup-and-recovery.md)). |+| CC9.2 Vendors and partners | [Vendor duties](vendor-duties.md) lists each service and its report. | Their SOC 2 reports and terms. | A vendor review each year ([vendor management policy](policies/vendor-management.md)). |++## A1 Availability++| Criterion | SignuDoc | Vendors | Yours |+| --------------------------------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------- |+| A1.1 Capacity | Free-plan limits are documented in the README ("What it costs"); the app stops cleanly at a vendor's limit. | Vercel and Neon scale with your plan. | Watch usage against your plans' limits, and move up before you reach them. |+| A1.2 Environmental protections, backups | Daily backup with retention, refused if pointed at the app's own store. | Vercel and Neon redundancy, in their reports. | Keep the backup store in another Vercel team. Keep billing current on every vendor. |+| A1.3 Recovery testing | A restore script that refuses a database with data in it, and loads in one transaction. | | Test a restore at least yearly and keep the record. |++## C1 Confidentiality++| Criterion | SignuDoc | Vendors | Yours |+| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------ |+| C1.1 Identifying and protecting confidential information | Documents are stored in a private store and only shown to their sender, their signers (through their own link) and, for finished records handed over, administrators. Download links expire. `AUDIT_LOG=off` keeps email and IP addresses out of function logs. | Encryption at rest (Vercel Blob, Neon). | Classify the documents you send, and decide who may be an administrator. |+| C1.2 Disposal | Retention rules (see CC6.5). | | Set them to your schedule. |++## PI1 Processing integrity++| Criterion | SignuDoc | Yours |+| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |+| PI1.1 to PI1.5 Inputs, processing, outputs, storage | Each finished document is sealed (PAdES), so any change after signing shows in a PDF reader. A certificate of completion lists who signed, when, from where, and how they were identified. Both audit trails are hash chains that show a changed, removed or reordered row. | Review exceptions (broken chains, failed seals) as incidents. |++## P Privacy++SOC 2 privacy (P1 to P8) follows your privacy notice. SignuDoc helps with: a consent to sign electronically before signing, an account export window before deletion, retention rules, and deletion of closed accounts. Data subject requests (access, correction, deletion) are handled by an administrator with the database or the app; there is no self-service request form. See [docs/self-hosting.md](../self-hosting.md#running-in-the-eu) for running in the EU.++## Known gaps++What an auditor may raise, and what to do:++| Gap | What to do |+| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |+| Someone with full database access can rewrite an audit chain consistently. | Limit Neon console access, and keep audit trails outside the database: the SIEM copy, or monthly CSVs. |+| No SAML (OIDC only). | Okta, Entra ID and Google all offer OIDC for the same application. |+| No SCIM provisioning. A person removed in your identity provider keeps their account row. | They cannot sign in again with SSO and password sign-in off. Review accounts under People quarterly. |+| No IP allow list in the app. | Vercel Firewall rules, on a Vercel plan that has them. |+| Signers outside your organization sign through an emailed link. | Turn on the signer check (emailed code or access code) for documents that need it. |+| No third-party penetration test of SignuDoc itself. | Commission one of your own install if your customers ask. |diff --git a/docs/soc2/policies/README.md b/docs/soc2/policies/README.mdnew file mode 100644index 0000000..d2fe327--- /dev/null+++ b/docs/soc2/policies/README.md@@ -0,0 +1,15 @@+# Sample policies++Short starting points for the policies a SOC 2 auditor asks to see, written for an organization that runs a SignuDoc install. They are not legal advice and not complete policies for your whole organization: fold them into your own policy set, fill in each `[bracket]`, have them approved, and review them yearly.++| Policy | Criteria |+| --------------------------------------------------- | ----------------- |+| [Access control](access-control.md) | CC6.1 to CC6.3 |+| [Change management](change-management.md) | CC8.1 |+| [Logging and monitoring](logging-and-monitoring.md) | CC4, CC7.2 |+| [Incident response](incident-response.md) | CC7.3 to CC7.5 |+| [Backup and recovery](backup-and-recovery.md) | CC9.1, A1.2, A1.3 |+| [Data retention](data-retention.md) | CC6.5, C1.2 |+| [Vendor management](vendor-management.md) | CC9.2 |++Each says who owns it, what must happen, and what evidence shows it did.diff --git a/docs/soc2/policies/access-control.md b/docs/soc2/policies/access-control.mdnew file mode 100644index 0000000..690afc4--- /dev/null+++ b/docs/soc2/policies/access-control.md@@ -0,0 +1,14 @@+# Access control policy++**Owner:** `[system owner]`. **Applies to:** the SignuDoc install, and the Vercel team, Neon project, Resend account and GitHub repository behind it.++1. **Sign-in.** Staff sign in through `[identity provider]` single sign-on, with MFA enforced there. Password sign-in is off (`PASSWORD_SIGN_IN=off`) except for `[two]` named break-glass administrator accounts, which use two-step sign-in. Without single sign-on, two-step sign-in is required for everyone.+2. **Sessions** end after `[30]` minutes without use and at most `[12]` hours after sign-in.+3. **Who gets an account.** Sign-up is limited to `[our domains]`. With single sign-on, a person is given the app in `[identity provider]` by `[role]` on request from their manager.+4. **Administrators.** At most `[N]` people are administrators, named in `[location]`. A new administrator is approved by `[role]` and made one by an existing administrator; the change is in the site audit trail.+5. **Vendor consoles.** Only `[roles]` are members of the Vercel team, Neon project, Resend account and GitHub repository. Each uses their own login with MFA. Shared logins are not allowed.+6. **Leavers.** On a person's last day, `[role]` removes them in `[identity provider]` and from every vendor console, and checks People in the app.+7. **Review.** Every `[quarter]`, `[role]` compares People, the administrator list and each vendor console's members against current staff, removes anyone who should not be there, and files the result.+8. **Break-glass accounts** are used only when single sign-on is down. Each use is recorded as an incident, and the password is changed after.++**Evidence:** access reviews, identity provider assignment and removal logs, the site audit trail (`role_changed`, `sign_in_succeeded` with `method`).diff --git a/docs/soc2/policies/backup-and-recovery.md b/docs/soc2/policies/backup-and-recovery.mdnew file mode 100644index 0000000..91ef117--- /dev/null+++ b/docs/soc2/policies/backup-and-recovery.md@@ -0,0 +1,12 @@+# Backup and recovery policy++**Owner:** `[system owner]`.++1. **Objectives:** recovery point `[24 hours]`, recovery time `[N hours]`.+2. **Database:** Neon point-in-time restore on a plan with at least `[7]` days of history.+3. **Daily backup:** SignuDoc's built-in backup copies the database and every file to a private Blob store in the Vercel team `[name]`, separate from the install's team, keeping `[30]` days ([Backup and restore](../../backup-and-restore.md)). Only `[roles]` are members of that team.+4. **Monitoring:** a missing or failed backup raises an alert ([logging and monitoring](logging-and-monitoring.md)).+5. **Restore test:** every `[year]`, `[role]` restores the newest backup into a new Neon project and Blob store, signs in, opens a finished document, checks its audit trail, records the time taken, and deletes the test copy.+6. **Secrets:** `BETTER_AUTH_SECRET` and the backup token are kept in `[password manager]`, readable by `[roles]`, so a restore does not depend on one person.++**Evidence:** the backup store's contents, backup alerts, restore test records.diff --git a/docs/soc2/policies/change-management.md b/docs/soc2/policies/change-management.mdnew file mode 100644index 0000000..e1ffb6a--- /dev/null+++ b/docs/soc2/policies/change-management.md@@ -0,0 +1,12 @@+# Change management policy++**Owner:** `[system owner]`.++1. The install deploys from `[branch]` of `[our repository]`. That branch is protected: changes arrive only by pull request, with `[one]` approval from someone other than the author, and the CI checks passing.+2. **SignuDoc updates** arrive as a pull request from the Update SignuDoc workflow. The reviewer reads the changelog for the releases it brings, notes any security fixes and database changes, checks the Vercel preview, and approves.+3. Security releases are taken within `[7]` days of their release; others within `[30]` days.+4. **Our own changes** to the code follow the same path, and are described in the pull request.+5. **Settings** changed in the app (Settings, Organization) are recorded in the site audit trail. Changes to environment variables in Vercel are approved by `[role]` and recorded in `[location]`, and take effect at the next deployment.+6. **Rollback:** if a deployment misbehaves, `[role]` promotes the previous deployment in Vercel and opens an incident. A release that changed the database is rolled forward with a fix instead, unless the change notes say it can be undone.++**Evidence:** merged pull requests with their approvals and checks, the changelog, Vercel's deployment history.diff --git a/docs/soc2/policies/data-retention.md b/docs/soc2/policies/data-retention.mdnew file mode 100644index 0000000..390ad11--- /dev/null+++ b/docs/soc2/policies/data-retention.md@@ -0,0 +1,12 @@+# Data retention policy++**Owner:** `[records owner]`.++1. Signed documents, their certificates and audit trails are kept for `[period]`, set under Settings, Organization, and then deleted by the daily cleanup.+2. Drafts that were never sent are deleted after `[the period the app uses]`.+3. A closed account is deleted 30 days after it is closed, once its owner has had the chance to export. Its finished documents pass to an administrator first, because they are the organization's records.+4. Backups keep copies of deleted files for `[30]` days more, then remove them.+5. Copies outside the app (downloads, files in `[record system]`, SIEM logs) follow `[our records schedule]`.+6. A legal hold stops deletion: `[role]` turns retention off for the period and records why.++**Evidence:** the retention setting, the daily job's summary, the site audit trail.diff --git a/docs/soc2/policies/incident-response.md b/docs/soc2/policies/incident-response.mdnew file mode 100644index 0000000..eca6f0b--- /dev/null+++ b/docs/soc2/policies/incident-response.md@@ -0,0 +1,18 @@+# Incident response policy++**Owner:** `[security owner]`. **Deputy:** `[name]`.++1. **What counts:** a suspected misused account, a broken audit chain, a failed seal or restore, data sent to the wrong person, an outage, a vendor's incident notice, or a SignuDoc security release that affects us.+2. **Report** to `[channel / address]`. Anyone may report.+3. **Contain**, as fits:+ - a misused account: remove it in the identity provider, or reset its two-step sign-in under People (which signs it out everywhere); change break-glass passwords;+ - a document sent wrongly: void it;+ - a leaked secret: rotate it in Vercel (`BETTER_AUTH_SECRET` signs everyone out and resets two-step sign-in, so rotate it only when it leaked), and deploy;+ - a bad deployment: promote the previous one.+4. **Assess** which records and people are affected, using both audit trails and the SIEM.+5. **Notify** affected customers within `[72 hours]` of confirming an incident that affects their data, and regulators where the law requires.+6. **Recover**, from backup if needed ([Backup and restore](../../backup-and-restore.md)).+7. **Close** with a written review: cause, impact, fixes, and follow-up actions with owners.+8. **Test** this plan once a year with a tabletop exercise.++**Evidence:** incident records and reviews, the yearly test.diff --git a/docs/soc2/policies/logging-and-monitoring.md b/docs/soc2/policies/logging-and-monitoring.mdnew file mode 100644index 0000000..1bd3515--- /dev/null+++ b/docs/soc2/policies/logging-and-monitoring.md@@ -0,0 +1,15 @@+# Logging and monitoring policy++**Owner:** `[security owner]`.++1. A Vercel log drain sends the install's function logs to `[SIEM]`, which keeps them for `[1 year]`.+2. Alerts go to `[channel or on-call]` for these lines (each is JSON with `"source": "signudoc"`):+ - `type` `audit`, `event` `sign_in_locked`: repeated wrong passwords for one address.+ - More than `[20]` `sign_in_failed` in `[10 minutes]`: a guessing attack.+ - `role_changed`, `two_factor_requirement_changed`, `settings_changed`, `part11_mode_changed`: a change to who can do what. Confirmed with the person who made it.+ - `type` `security`, `category` `backup_failure`, `backup_finished` with `level` `error`, or `retention_job_failure`: a daily job failed.+ - No `backup_finished` line in `[26 hours]`: the backup did not run.+3. Every `[month]`, `[role]` checks that both audit chains are intact (Settings, Organization, Sign-in security; and a sample of documents), downloads the site audit trail CSV and files it in `[location]`, and looks for anything unexpected.+4. An alert that is not explained becomes an incident.++**Evidence:** the drain and alert configuration, alert tickets, the monthly review record.diff --git a/docs/soc2/policies/vendor-management.md b/docs/soc2/policies/vendor-management.mdnew file mode 100644index 0000000..ce3e8d5--- /dev/null+++ b/docs/soc2/policies/vendor-management.md@@ -0,0 +1,11 @@+# Vendor management policy++**Owner:** `[security owner]`.++1. Before a new vendor holds our data or runs part of the install, `[role]` reviews its security report, terms and data processing agreement, and records the result ([Vendor duties](../vendor-duties.md#vendor-review-record)).+2. Every `[year]`, `[role]` reviews each vendor's current SOC 2 report (period, opinion, exceptions), checks we still meet the complementary user entity controls it lists, and records the review.+3. A vendor's incident notice is handled under the [incident response policy](incident-response.md).+4. Billing for every vendor is kept current, and on a company card owned by `[role]`, so a lapsed payment cannot take records offline.+5. SignuDoc itself is reviewed as an open-source component: each release is read before it is taken ([change management](change-management.md)).++**Evidence:** vendor review records, current reports on file.diff --git a/docs/soc2/questionnaire.md b/docs/soc2/questionnaire.mdnew file mode 100644index 0000000..ba6cdb8--- /dev/null+++ b/docs/soc2/questionnaire.md@@ -0,0 +1,79 @@+# Questionnaire answers++Answers to the questions customer security questionnaires (SIG Lite, CAIQ, and the ones companies write themselves) ask most often, for a SignuDoc install set up as the [setup checklist](README.md#setup-checklist) describes. Replace each `[bracket]` with your own facts, and change any answer that is not true of your install. An answer you cannot back with evidence is worse than "no".++## Company and scope++**Do you have a SOC 2 report?**+`[Our organization's SOC 2 Type 2 report covers the e-signature service.]` Or, if not: the service runs on Vercel, Neon and Resend, each of which has its own SOC 2 Type 2 report, available under NDA. We run SignuDoc, an open-source e-signature application, on our own accounts with those vendors; no other company handles your documents.++**Who hosts the service, and where is data stored?**+Vercel (application and file storage) in `[region]`, Neon (Postgres database) in `[region]`, and Resend (email) in `[region]`. All three are under contract with `[us]`.++**Do you use subprocessors?**+Yes: Vercel, Neon and Resend `[and any optional ones: identity provider, SIEM, signing provider]`. See [vendor duties](vendor-duties.md).++## Access control++**Do you support single sign-on?**+Yes, OpenID Connect with any compliant identity provider, including Okta, Microsoft Entra ID and Google Workspace. `[Password sign-in is turned off; only two named administrators keep a password for emergency access.]` SAML is not supported.++**Do you support multi-factor authentication?**+Yes. With single sign-on, your identity provider's MFA applies. For password sign-in, two-step sign-in with an authenticator app (TOTP) and single-use backup codes, which `[is required for every account]`.++**What are your password rules?**+At least 15 characters, at most 128, checked against the Have I Been Pwned breach list (k-anonymity: only a hash prefix leaves the server). Hashed with scrypt. Ten wrong passwords for one address within 15 minutes lock that address for 15 minutes.++**How do you limit sessions?**+Sessions end after `[30 minutes]` without use and at most `[12 hours]` after sign-in. A user can sign out every device at once. Ending a session takes effect on the next request.++**How is access granted and removed?**+Accounts are limited to `[our email domains]`. With single sign-on, access follows assignment in our identity provider: removing someone there stops their sign-in. Administrator rights are granted by another administrator and recorded in the audit trail. Access is reviewed `[quarterly]`.++**Is customer data separated between customers?**+`[This install serves only our organization.]` Within it, each sender sees only their own documents, and each signer reaches only the document they were sent, through a random single-use link.++## Data protection++**Is data encrypted in transit?**+Yes. HTTPS only, with HSTS. Database connections require TLS.++**Is data encrypted at rest?**+Yes, by the storage providers: Vercel Blob and Neon encrypt stored data. Authenticator secrets and backup codes are also encrypted by the application.++**Can documents be tampered with after signing?**+Each finished document is sealed with a PAdES signature `[from our own certificate / from a certificate authority, with a trusted timestamp and long-term validation]`, so any change shows in Adobe Acrobat and other PDF readers. A certificate of completion lists each signer, time, IP address and identity check.++**How long do you keep data, and how is it deleted?**+Finished documents are deleted `[N days]` after completion `[or: kept until deleted by hand]`, by a daily job. Closed accounts are deleted after a 30-day export window. Backups keep copies of deleted files for `[30]` more days.++## Logging and monitoring++**Do you keep audit logs?**+Yes. Each document has its own audit trail (created, sent, viewed, consented, identity checks, signed, declined, voided, completed). The install has another for sign-ins and failed sign-ins (with IP address and reason), lockouts, sign-outs, password and two-step changes, role and settings changes, and account closures. Both are hash chains, so a changed or removed entry shows, and both export as CSV.++**Are logs sent to a SIEM?**+`[Yes: every audit entry and security event is sent as structured JSON to our SIEM through a Vercel log drain, where we alert on lockouts, role changes and settings changes.]`++**How long are logs kept?**+The audit trails in the database are kept with the records they describe. `[Our SIEM keeps the copies for N days.]`++## Operations++**How are changes deployed?**+Through pull requests to our copy of the code, reviewed by `[a second person]` before merging. Each change gets a preview deployment first. Every deployment is kept and can be rolled back. Database changes are versioned migrations applied by the production build.++**How do you handle vulnerabilities?**+We take each SignuDoc release `[within N days, and security fixes within N days]`. The SignuDoc repository runs CodeQL, dependency review and `npm audit`, and each release has an SBOM and signed build provenance. `[We run our own penetration test yearly.]`++**Do you have backups, and do you test them?**+Yes. Neon keeps point-in-time history for `[N days]`. A daily backup copies the database and every file to a separate storage account `[in another Vercel team]`, kept `[30]` days. We test a full restore `[yearly]`, most recently on `[date]`.++**What are your RPO and RTO?**+`[RPO 24 hours from the daily backup, or less from Neon's point-in-time restore. RTO N hours.]`++**Do you have an incident response plan?**+`[Yes, tested yearly.]` See our [incident response policy](policies/incident-response.md). We notify affected customers within `[72 hours]` of confirming an incident that affects their data.++**What is your uptime?**+`[As measured by our monitoring.]` The service depends on Vercel and Neon; see their status pages and SLAs `[on our plans]`.diff --git a/docs/soc2/vendor-duties.md b/docs/soc2/vendor-duties.mdnew file mode 100644index 0000000..d6d1f92--- /dev/null+++ b/docs/soc2/vendor-duties.md@@ -0,0 +1,69 @@+# Vendor duties++A SignuDoc install on Vercel runs on the services below. For your SOC 2 audit they are subservice organizations: your auditor usually carves them out, which means you collect each one's SOC 2 report, check its opinion and exceptions, and show that you do the complementary user entity controls (CUECs) the report says customers must do.++What each vendor offers, and which plan includes its report, was checked on 2026-11-16. It changes; check again before an audit.++## Required services++### Vercel (hosting, functions, Blob storage, cron, logs)++- **Holds:** the running app, build and runtime logs, every PDF in the Blob store (originals, sealed copies, certificates), and the backup store if you keep it on Vercel.+- **Report:** SOC 2 Type 2 (Security, Confidentiality, Availability). Available to Pro and Enterprise teams under Team Settings, Compliance, or through security.vercel.com. Not available to Hobby teams.+- **Shared responsibility:** Vercel's model is at https://vercel.com/docs/security/shared-responsibility. Read it with the CUEC section of the report.+- **CUECs you will typically need to show:**+ - Team membership limited to the people who run the install, each with MFA, reviewed regularly. Single sign-on to the Vercel team itself is a paid Vercel add-on on Pro; without it, require MFA on each member's Vercel account.+ - Environment variables that hold secrets marked Sensitive.+ - Deployment protection on preview deployments, so previews of unmerged changes are not public.+ - A log drain, if your monitoring relies on logs: runtime logs on their own are kept for a short time (about a day on Pro).+ - Team audit logs (who changed what in the Vercel team) are an Enterprise feature. On Pro, record team changes yourself.++### Neon (Postgres, through the Vercel Marketplace)++- **Holds:** every account, document record, setting and both audit trails.+- **Report:** SOC 2 Type 2, through trust.neon.com. Neon's pricing page lists SOC 2 among the features of its Scale plan; check which plan your report access and the controls you need come with.+- **CUECs you will typically need to show:**+ - Console and project access limited and reviewed. Someone with full database access can change rows, including rewriting an audit chain consistently, so this matters more than usual.+ - A restore window that meets your recovery point objective (short on the free plan, longer on paid plans), and SignuDoc's own daily backup on top.+ - The region chosen for your data residency needs.++### Resend (email, through the Vercel Marketplace)++- **Holds:** delivery logs of every email (invitations, codes, reminders, completion notices) and their content for a time.+- **Report:** SOC 2 Type II (period 2025-02-01 to 2026-02-01 when checked), under Settings, Documents in the Resend dashboard. The site does not say which plans include it; ask Resend if yours does not show it.+- **CUECs you will typically need to show:**+ - Your own verified sending domain, with SPF and DKIM.+ - Account access limited and reviewed. Single sign-on to Resend is a paid add-on.+ - Email treated as a notification, not the record. The record is in the database and the sealed PDFs.++## Optional services++Only if you turn them on. Each is outside Vercel and set up by you.++| Service | When | What to collect |+| ----------------------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------ |+| Your identity provider (Okta, Entra ID, Google) | Single sign-on (`SSO_ISSUER`) | You already have it in scope. Note that removing someone there removes their access here. |+| A SIEM or log service | A Vercel log drain | Its report, and the retention you set. |+| eID Easy, or a trust service provider (CSC API) | Signatures in the signers' own names | Their eIDAS qualification (the EU trusted list) and security report, if signed records depend on them. |+| A certificate authority and timestamp server | `SEAL_P12_BASE64`, `SEAL_TIMESTAMP_URL` | Their certificate policy and, for a qualified seal, their place on the EU trusted list. |+| A second Vercel team for backups | `BACKUP_BLOB_READ_WRITE_TOKEN` | Covered by Vercel's report. Record who has access to that team; keep it smaller than the main team. |++## The SignuDoc project++SignuDoc is open-source software, provided as is under its license, with no supplier agreement, support commitment or SOC 2 report of its own. It never receives your data: there is no SignuDoc service between your install and your vendors. For your audit, treat it like any other open-source component you build from:++- You choose when to take a release, and review it (the update workflow opens a pull request with the changelog).+- Each release from v0.3.0 has an SBOM and signed build provenance you can verify ([SECURITY.md](../../SECURITY.md#verifying-a-release)).+- The repository's own checks (CodeQL, dependency review, `npm audit`, OpenSSF Scorecard) are described in [SECURITY.md](../../SECURITY.md#how-the-code-is-checked).++## Vendor review record++Once a year, and when you add a vendor, record for each:++- Vendor, service and plan: `[ ]`+- Data held, and its region: `[ ]`+- Report reviewed (type, period, opinion), and exceptions noted: `[ ]`+- CUECs from the report, and how you meet each: `[ ]`+- Contract and data processing terms in place: `[ ]`+- Who in your organization has access: `[ ]`+- Reviewed by `[name, role, date]`. Next review: `[date]`diff --git a/src/components/settings/security-panel.tsx b/src/components/settings/security-panel.tsxindex 826bc9e..eee9784 100644--- a/src/components/settings/security-panel.tsx+++ b/src/components/settings/security-panel.tsx@@ -21,6 +21,8 @@ type AuditResponse = {} | null;const EVENT_LABELS: Record<SystemAuditEvent["event"], string> = {+ account_closure_requested: "Account closure requested",+ account_deleted: "Account deleted",email_domain_changed: "Email domain changed",identity_verification_revoked: "Identity confirmation taken back",identity_verified: "Identity confirmed",diff --git a/src/lib/account-purge.dbtest.ts b/src/lib/account-purge.dbtest.tsindex 09ec324..5c0ad16 100644--- a/src/lib/account-purge.dbtest.ts+++ b/src/lib/account-purge.dbtest.ts@@ -169,6 +169,14 @@ test("an envelope completed while its sender's account is being deleted goes toassert.ok(!summary.accountPurgeFailures.includes(leaver));assert.equal(await accountExists(leaver), false);+ // The deletion is in the install's audit trail.+ const deleted = await database.query<{ target_user_id: string }>(+ `select target_user_id from system_audit_events where event = 'account_deleted' and target_user_id = $1`,+ [leaver],+ );++ assert.equal(deleted.rows.length, 1);+// The signed record outlives the account, with its document.const kept = await envelopeRow(envelope.id);diff --git a/src/lib/account.ts b/src/lib/account.tsindex 10107fd..ee40d6d 100644--- a/src/lib/account.ts+++ b/src/lib/account.ts@@ -19,6 +19,7 @@ import {} from "./retention.ts";import { resolvePublicSupportAddress } from "./public-contact.ts";import { createEmailService } from "./services/email.ts";+import { recordSystemAuditEvent } from "./services/system-audit.ts";import { getBranding } from "./settings.ts";import { type EnvSource } from "./utils/env.ts";@@ -237,6 +238,22 @@ export async function requestAccountClosure(const closureSchedule = await scheduleAccountClosure(userId, database);if (!closureSchedule.alreadyQueued) {+ await recordSystemAuditEvent(+ {+ actorEmail: account.email,+ actorUserId: userId,+ event: "account_closure_requested",+ metadata: { purgeAfterAt: closureSchedule.purgeAfterAt },+ targetUserId: userId,+ },+ database,+ ).catch((error: unknown) => {+ console.error(+ `Failed to record the account closure request for user ${userId}:`,+ error,+ );+ });+const submittedAt = formatRetentionDeadline(closureSchedule.requestedAt);const exportExpiresAt = formatRetentionDeadline(closureSchedule.exportExpiresAt,diff --git a/src/lib/retention.ts b/src/lib/retention.tsindex 534b5a9..7a77457 100644--- a/src/lib/retention.ts+++ b/src/lib/retention.ts@@ -15,6 +15,7 @@ import {type StorageService,} from "./services/storage.ts";import { createEmailService, type EmailService } from "./services/email.ts";+import { recordSystemAuditEvent } from "./services/system-audit.ts";import { readStoredSettings } from "./settings.ts";import { type EnvSource, isHostedMode, resolveAppUrl } from "./utils/env.ts";@@ -620,6 +621,29 @@ async function deleteAccountRows(storageKeys.add(template.sourcePdfKey);}+ // The access it ends is worth a line in the install's trail, which lands+ // or rolls back with the delete. The hosted service keeps nothing of a+ // closed account, its address included.+ const closed = await queryOne<{ email: string }>(+ database,+ `SELECT email FROM "user" WHERE id = $1`,+ [userId],+ );++ await recordSystemAuditEvent(+ {+ actorEmail: null,+ actorUserId: null,+ event: "account_deleted",+ metadata: {+ email: keepFinishedEnvelopes ? (closed?.email ?? null) : null,+ reason: "closure_requested",+ },+ targetUserId: userId,+ },+ database,+ );+await database.query(`DELETE FROM "user"diff --git a/src/lib/services/system-audit.ts b/src/lib/services/system-audit.tsindex a7e5783..b68cbfa 100644--- a/src/lib/services/system-audit.ts+++ b/src/lib/services/system-audit.ts@@ -18,6 +18,8 @@ import { canonicalJson } from "../utils/canonical-json.ts";// changed, removed or reordered row shows.export const systemAuditEventTypes = [+ "account_closure_requested",+ "account_deleted","settings_changed","part11_mode_changed","role_changed",