Cratis security review
Event sourcing changes the shape of a security review. A mistake in an ordinary
application is a bug you fix; a secret written into an append is a fact that
lives in the log forever and cannot be edited out. The event-sourcing section
below is the one that is specific to this stack, and it is the one worth reading
first.
Verified product sources
| Package |
Purpose |
Cratis.Arc.Chronicle |
[NotAudited] in Cratis.Arc.Chronicle.Commands; the ARCCHR0009 analyzer |
Cratis.Chronicle |
[PII], [Subject], redaction, namespace isolation |
Cratis.Chronicle |
[Encrypted] in Cratis.Chronicle.ProtectedValues; analyzers CHR0052, CHR0053 |
Cratis.Arc.Core |
Authorization filters, CommandResult.Unauthorized |
Every Arc check is cited in references/arc-boundaries.md.
Reverify against the owning product repository before asserting a framework
guarantee this file does not already state.
When to run this review without being asked
The orchestrating agents and the PR-review prompt run it unconditionally as the
last gate. When you are shipping directly — one agent, one branch — run it
yourself before committing whenever the diff adds or removes a line carrying
any of: [Roles], [Authorize], [AllowAnonymous], [ExecuteCommandsAsSystem];
[PII], [Subject], [NotAudited]; useIdentity; or a secret-shaped identifier
(ConnectionString, PrivateKey, Bearer, Password, ApiKey, AccessToken).
Added or removed matters: a deleted [PII] or [Roles] is the change most
worth a second pair of eyes. Match changed lines, not whole files — every slice
contains a [Command] and an [EventType], and a trigger that fires on every
commit is a trigger that gets skipped. A name-based list has the same blind spot
as ARCCHR0009: a secret with an innocuous property name passes it, so read the
command's properties as well as grepping them.
Route near misses
- General correctness and maintainability: use
cratis-code-review.
- Scalability and resource use: use
cratis-performance-review.
- Implementing authentication, authorization or identity: use
cratis-arc-authentication-authorization-and-identity. This skill reviews;
it does not build.
- Compliance mechanics —
[PII], subject resolution, erasure, redaction: use
cratis-chronicle-compliance.
Step 1 — Event sourcing: the permanent-record checks
- Every
[Command] property holding a secret or credential is marked [NotAudited]; a retained operational secret is also [Encrypted] on the event, and a credential reaches the event only as a hash or a reference. A
command's property values are written to the causation of every event it
appends, and causation is as permanent as the events. Prefer the marking on
the concept type so it travels everywhere the value appears. [NotAudited]
alone leaves the secret in plaintext on events; [Encrypted] alone leaves the
command input on the causation chain.
ARCCHR0009 catches properties whose names read as secrets — so read the
properties whose names do not say what they hold, because the analyzer cannot.
- Personal data is
[PII] alone, a secret is [Encrypted] plus [NotAudited].
They are different mechanisms with different consequences: [NotAudited]
withholds a value from the causation chain; [Encrypted] encrypts it at rest
without erasure; [PII] encrypts, enrolls it in per-subject erasure and
withholds it. A third-party API key is [Encrypted] + [NotAudited]. An email address is
[PII]. A password is stored as a hash, never as a retained secret. Never combine [PII] with [Encrypted] (CHR0053), and neither goes
on an event-source id (CHR0034, CHR0052).
- Credentials used for authentication (passwords, bearer or session tokens) are never stored; keep a hash or a reference. An operational secret the system must retain and use (a third-party API key, a company's bank account number) is stored only as an
[Encrypted] + [NotAudited] concept, and never in a read model returned to clients in plaintext.
- Event-source ids are generated server-side, never accepted from an untrusted
client where the id grants access to a stream.
- Upcasting and event-type migration logic cannot introduce a property the
original contract did not carry.
- Uniqueness cannot be bypassed by concurrent writes — it is enforced by a
Chronicle constraint, not by a read-model pre-check.
- Cross-tenant writes cannot bypass a constraint that is scoped per namespace.
Step 2 — Input validation and injection
- Every command property is validated before use — null, empty, range, format.
- No raw SQL concatenation; parameterized queries or EF Core only.
- No user-supplied value reaches
Path.Combine, a File.* call, a shell
command, or process arguments.
- No user-supplied value becomes an event-store key without sanitization.
Step 3 — Authentication and authorization
- Every exposed endpoint is either authorized or explicitly anonymous with a
stated reason.
- Authorization is expressed at the boundary — an attribute, a policy, a command
filter — never as an
if on roles inside Handle().
- Tenant isolation holds: no cross-namespace data is reachable without
authorization.
- Claims are verified before acting on identity-dependent command data. A client
must not be able to assert who it is through a command property.
- Note that an unauthorized command result maps to HTTP 403, not 401 — a
reviewer reading logs for 401s will miss authorization failures.
- Review Arc-specific security boundaries when
the diff touches hosting, identity, policies, discovery, streams or system actors.
It ties the checks to Arc source; do not assume a clean analyzer run proves
those deployment boundaries.
Step 4 — Data exposure
- No personal data is returned to a caller that did not supply it.
- Query results are scoped to the requesting tenant and user. A query that can
return all-tenant data is a finding even when no current caller reaches it.
- Response payloads carry only fields the client uses. Over-fetching is an
exposure surface, not only a performance one.
- A managed read-model document holds one subject's personal data. Mixing
several people's data in one document breaks erasure.
Step 5 — Secrets and configuration
- No secret in source, in a configuration file, or in a specification fixture.
- Secrets come from environment variables or a secrets manager.
- No hard-coded connection string outside test code.
Step 6 — Frontend
- No user-supplied value in
dangerouslySetInnerHTML.
- No token or secret in
localStorage — use an httpOnly cookie or in-memory
state.
- Command payloads carry only the minimum required fields.
- No client-side access control that is not also enforced server-side. A
disabled button is a usability affordance, never a control.
Step 7 — Report
Read and use .cratis/ai/rules/review-reports.md when writing the report.
Keep the security risk label on each finding:
| Risk |
Shared classification |
| Critical |
Blockers: exploitable exposure requiring correction before merge |
| Medium |
Suggestions: conditional exposure; state what makes it non-critical |
| Low |
Suggestions: defense-in-depth improvement |
Use the shared verdict vocabulary, not a separate security verdict. If a
conditional exposure must be corrected before merge, classify it as Critical
and explain the exploit conditions rather than leaving a blocker under Medium.
What breaks
- A finding is a policy preference in framework clothing. Which roles exist,
which data is sensitive, and which retention applies are the product's calls,
not the framework's. State them as policy questions for the owner, not as
contracts.
[NotAudited] is used for personal data. The value stays out of causation
but is never encrypted and never enrolled in erasure — the opposite of what a
subject-rights request needs.
- The review assumes the analyzer covered the secrets.
ARCCHR0009 matches
names. A property called Value holding an API key passes it silently.
- A missing check is reported as "verified". Unknown is not pass. If a
surface could not be reached, say so as
indeterminate rather than omitting
it.
How it is proven
The build and specifications are green before the report is written; each
finding cites the file and line; and the report states explicitly which
surfaces were and were not examined.
1---2name: cratis-security-review-23description: Use when auditing a Cratis application change for security, especially permissions, untrusted input, secrets or permanent event-log exposure. Not for implementing authentication or general style review.4license: MIT5metadata:6 source: https://skillmd.com/skills/cratis/cratis-security-review-27---89# Cratis security review1011Event sourcing changes the shape of a security review. A mistake in an ordinary12application is a bug you fix; a secret written into an append is a fact that13lives in the log forever and cannot be edited out. The event-sourcing section14below is the one that is specific to this stack, and it is the one worth reading15first.1617## Verified product sources1819| Package | Purpose |20| --- | --- |21| `Cratis.Arc.Chronicle` | `[NotAudited]` in `Cratis.Arc.Chronicle.Commands`; the `ARCCHR0009` analyzer |22| `Cratis.Chronicle` | `[PII]`, `[Subject]`, redaction, namespace isolation |23| `Cratis.Chronicle` | `[Encrypted]` in `Cratis.Chronicle.ProtectedValues`; analyzers `CHR0052`, `CHR0053` |24| `Cratis.Arc.Core` | Authorization filters, `CommandResult.Unauthorized` |2526Every Arc check is cited in references/arc-boundaries.md.2728Reverify against the owning product repository before asserting a framework29guarantee this file does not already state.3031## When to run this review without being asked3233The orchestrating agents and the PR-review prompt run it unconditionally as the34last gate. When you are shipping directly — one agent, one branch — run it35yourself before committing whenever the diff **adds or removes** a line carrying36any of: `[Roles]`, `[Authorize]`, `[AllowAnonymous]`, `[ExecuteCommandsAsSystem]`;37`[PII]`, `[Subject]`, `[NotAudited]`; `useIdentity`; or a secret-shaped identifier38(`ConnectionString`, `PrivateKey`, `Bearer`, `Password`, `ApiKey`, `AccessToken`).39Added *or removed* matters: a deleted `[PII]` or `[Roles]` is the change most40worth a second pair of eyes. Match changed lines, not whole files — every slice41contains a `[Command]` and an `[EventType]`, and a trigger that fires on every42commit is a trigger that gets skipped. A name-based list has the same blind spot43as `ARCCHR0009`: a secret with an innocuous property name passes it, so read the44command's properties as well as grepping them.4546## Route near misses4748- General correctness and maintainability: use `cratis-code-review`.49- Scalability and resource use: use `cratis-performance-review`.50- Implementing authentication, authorization or identity: use51 `cratis-arc-authentication-authorization-and-identity`. This skill reviews;52 it does not build.53- Compliance mechanics — `[PII]`, subject resolution, erasure, redaction: use54 `cratis-chronicle-compliance`.5556## Step 1 — Event sourcing: the permanent-record checks5758- **Every `[Command]` property holding a secret or credential is marked `[NotAudited]`; a retained operational secret is also `[Encrypted]` on the event, and a credential reaches the event only as a hash or a reference.** A59 command's property values are written to the causation of every event it60 appends, and causation is as permanent as the events. Prefer the marking on61 the concept type so it travels everywhere the value appears. `[NotAudited]`62 alone leaves the secret in plaintext on events; `[Encrypted]` alone leaves the63 command input on the causation chain.64 `ARCCHR0009` catches properties whose *names* read as secrets — so read the65 properties whose names do not say what they hold, because the analyzer cannot.66- **Personal data is `[PII]` alone, a secret is `[Encrypted]` plus `[NotAudited]`.**67 They are different mechanisms with different consequences: `[NotAudited]`68 withholds a value from the causation chain; `[Encrypted]` encrypts it at rest69 without erasure; `[PII]` encrypts, enrolls it in per-subject erasure and70 withholds it. A third-party API key is `[Encrypted]` + `[NotAudited]`. An email address is71 `[PII]`. A password is stored as a hash, never as a retained secret. Never combine `[PII]` with `[Encrypted]` (`CHR0053`), and neither goes72 on an event-source id (`CHR0034`, `CHR0052`).73- Credentials used for authentication (passwords, bearer or session tokens) are never stored; keep a hash or a reference. An operational secret the system must retain and use (a third-party API key, a company's bank account number) is stored only as an `[Encrypted]` + `[NotAudited]` concept, and never in a read model returned to clients in plaintext.74- Event-source ids are generated server-side, never accepted from an untrusted75 client where the id grants access to a stream.76- Upcasting and event-type migration logic cannot introduce a property the77 original contract did not carry.78- Uniqueness cannot be bypassed by concurrent writes — it is enforced by a79 Chronicle constraint, not by a read-model pre-check.80- Cross-tenant writes cannot bypass a constraint that is scoped per namespace.8182## Step 2 — Input validation and injection8384- Every command property is validated before use — null, empty, range, format.85- No raw SQL concatenation; parameterized queries or EF Core only.86- No user-supplied value reaches `Path.Combine`, a `File.*` call, a shell87 command, or process arguments.88- No user-supplied value becomes an event-store key without sanitization.8990## Step 3 — Authentication and authorization9192- Every exposed endpoint is either authorized or explicitly anonymous with a93 stated reason.94- Authorization is expressed at the boundary — an attribute, a policy, a command95 filter — never as an `if` on roles inside `Handle()`.96- Tenant isolation holds: no cross-namespace data is reachable without97 authorization.98- Claims are verified before acting on identity-dependent command data. A client99 must not be able to assert who it is through a command property.100- Note that an unauthorized command result maps to HTTP **403**, not 401 — a101 reviewer reading logs for 401s will miss authorization failures.102- Review [Arc-specific security boundaries](references/arc-boundaries.md) when103 the diff touches hosting, identity, policies, discovery, streams or system actors.104 It ties the checks to Arc source; do not assume a clean analyzer run proves105 those deployment boundaries.106107## Step 4 — Data exposure108109- No personal data is returned to a caller that did not supply it.110- Query results are scoped to the requesting tenant and user. A query that can111 return all-tenant data is a finding even when no current caller reaches it.112- Response payloads carry only fields the client uses. Over-fetching is an113 exposure surface, not only a performance one.114- A managed read-model document holds one subject's personal data. Mixing115 several people's data in one document breaks erasure.116117## Step 5 — Secrets and configuration118119- No secret in source, in a configuration file, or in a specification fixture.120- Secrets come from environment variables or a secrets manager.121- No hard-coded connection string outside test code.122123## Step 6 — Frontend124125- No user-supplied value in `dangerouslySetInnerHTML`.126- No token or secret in `localStorage` — use an `httpOnly` cookie or in-memory127 state.128- Command payloads carry only the minimum required fields.129- No client-side access control that is not also enforced server-side. A130 disabled button is a usability affordance, never a control.131132## Step 7 — Report133134Read and use `.cratis/ai/rules/review-reports.md` when writing the report.135Keep the security risk label on each finding:136137| Risk | Shared classification |138| --- | --- |139| **Critical** | Blockers: exploitable exposure requiring correction before merge |140| **Medium** | Suggestions: conditional exposure; state what makes it non-critical |141| **Low** | Suggestions: defense-in-depth improvement |142143Use the shared verdict vocabulary, not a separate security verdict. If a144conditional exposure must be corrected before merge, classify it as Critical145and explain the exploit conditions rather than leaving a blocker under Medium.146147## What breaks148149- **A finding is a policy preference in framework clothing.** Which roles exist,150 which data is sensitive, and which retention applies are the product's calls,151 not the framework's. State them as policy questions for the owner, not as152 contracts.153- **`[NotAudited]` is used for personal data.** The value stays out of causation154 but is never encrypted and never enrolled in erasure — the opposite of what a155 subject-rights request needs.156- **The review assumes the analyzer covered the secrets.** `ARCCHR0009` matches157 names. A property called `Value` holding an API key passes it silently.158- **A missing check is reported as "verified".** Unknown is not pass. If a159 surface could not be reached, say so as `indeterminate` rather than omitting160 it.161162## How it is proven163164The build and specifications are green before the report is written; each165finding cites the file and line; and the report states explicitly which166surfaces were and were not examined.