@openreachtech/hora-skills-ort-renchan 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/skills/hor-build-e2e-test-environment/SKILL.md +7 -1
- package/dist/skills/hor-mutation-resolver/SKILL.md +7 -7
- package/dist/skills/hor-mutation-resolver/references/errors.md +15 -18
- package/dist/skills/hor-query-resolver/SKILL.md +4 -5
- package/dist/skills/hor-query-resolver/references/errors-and-context.md +12 -16
- package/dist/skills/hor-security-audit/SKILL.md +2 -2
- package/dist/skills/hor-security-audit/references/secrets.md +62 -36
- package/package.json +4 -1
|
@@ -195,7 +195,13 @@ by default: `NODE_ENV=<stack-env>` selects the E2E stack's own values everywhere
|
|
|
195
195
|
on every command remembering to apply overrides.
|
|
196
196
|
|
|
197
197
|
The stack reads its own committed **`.env.<stack-env>`**, at the repository root beside the other
|
|
198
|
-
environments' files.
|
|
198
|
+
environments' files. Three rules govern that file:
|
|
199
|
+
|
|
200
|
+
- **It holds only values that reach the local machine.** It is a local env file, which may be
|
|
201
|
+
committed only on that condition: endpoints on `127.0.0.1` or `localhost`, placeholder credentials,
|
|
202
|
+
the connection of the stack's own database. An external host, a real staging or production endpoint,
|
|
203
|
+
or a key-shaped value — an API key, a token — never goes in it. This is the line the security
|
|
204
|
+
audit's checks 12 to 14 hold, and it reads the file to confirm it.
|
|
199
205
|
|
|
200
206
|
- **It is a complete, standalone description of the E2E stack.** Every key the application, the
|
|
201
207
|
tooling and the background processes read has to be present, because a missing key reads as `null`
|
|
@@ -146,12 +146,12 @@ The full template with every helper filled in is in
|
|
|
146
146
|
## 3. `errorCodeHash` and throwing errors
|
|
147
147
|
|
|
148
148
|
Declare every error the resolver can raise in `static get errorCodeHash ()`, spreading
|
|
149
|
-
`...super.errorCodeHash` first. Each entry maps an `ErrorName` to a **code string
|
|
150
|
-
|
|
149
|
+
`...super.errorCodeHash` first. Each entry maps an `ErrorName` to a **code string**, whose shape
|
|
150
|
+
and categories `hoc-error-codes` settles. The ones a mutation resolver reaches for:
|
|
151
151
|
|
|
152
|
-
- `203.*` — **
|
|
153
|
-
- `204.*` — **
|
|
154
|
-
- `
|
|
152
|
+
- `203.*` — **validational** (`InvalidXxx`). These pair with the validator's predicates (§6).
|
|
153
|
+
- `204.*` — **database record** (`XxxNotFound`, `NotAllowedToXxx`, `CurrentXxxIsSameAsTheNewOne`).
|
|
154
|
+
- `202.*` — **access right** (`InvalidCredentials`).
|
|
155
155
|
|
|
156
156
|
```js
|
|
157
157
|
/** @override */
|
|
@@ -173,7 +173,7 @@ static get errorCodeHash () {
|
|
|
173
173
|
The base turns this hash into constructable error classes on `this.errorHash` (via
|
|
174
174
|
`buildErrorHash()` in the factory). **Throw with `this.errorHash.<Name>.create()`** — validator
|
|
175
175
|
errors bubble out of `resolve()`; state errors are thrown from inside the transaction callback so
|
|
176
|
-
the transaction rolls back.
|
|
176
|
+
the transaction rolls back. Which category each error falls into, and the wiring, are in
|
|
177
177
|
[errors.md](./references/errors.md).
|
|
178
178
|
|
|
179
179
|
## 4. `generateTransactionCallback()` — one transaction, all writes
|
|
@@ -352,7 +352,7 @@ project-wide jest rules unchanged. Full placement detail in [testing.md](./refer
|
|
|
352
352
|
- [transaction.md](./references/transaction.md) — `generateTransactionCallback` in depth:
|
|
353
353
|
one-transaction rule, `beginTransaction`, nested-create `include`, existence guards, `.set()`+
|
|
354
354
|
`.save()` vs `.update()`, throwing state errors, post-commit side effects (§4)
|
|
355
|
-
- [errors.md](./references/errors.md) —
|
|
355
|
+
- [errors.md](./references/errors.md) — which category each error falls into,
|
|
356
356
|
`this.errorHash.<Name>.create()`, and how the base builds the error hash (§3)
|
|
357
357
|
- [dependency-injection.md](./references/dependency-injection.md) — `constructor` + `static create()`
|
|
358
358
|
+ `static createXxx()` factory helpers, when to inject, `buildErrorHash` wiring (§7)
|
|
@@ -22,28 +22,25 @@ static get errorCodeHash () {
|
|
|
22
22
|
// Database Errors
|
|
23
23
|
UserNotFound: '204.M024.001',
|
|
24
24
|
|
|
25
|
-
//
|
|
26
|
-
InvalidCredentials: '
|
|
25
|
+
// Access Right Errors
|
|
26
|
+
InvalidCredentials: '202.M024.001',
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- **`<seq>`** — a zero-padded running number within the resolver (`001`, `002`, …). Numbering is
|
|
45
|
-
usually contiguous within a category; a gap from a removed code is fine — do not renumber existing
|
|
46
|
-
codes (they may be referenced by clients).
|
|
31
|
+
## Which category an error falls into
|
|
32
|
+
|
|
33
|
+
The code string itself is settled by `hoc-error-codes` — its three parts, the categories the
|
|
34
|
+
leading one sorts a failure into, and the rule that a code already in use is never renumbered.
|
|
35
|
+
What a mutation resolver decides is which category each of its own errors belongs to, and where
|
|
36
|
+
that error is thrown from.
|
|
37
|
+
|
|
38
|
+
- **`203`, validational.** Names are `InvalidXxx` and correspond 1:1 to the validator's predicates
|
|
39
|
+
(`InvalidTitle` ↔ `isValidTitle`), per the project's resolver-validator conventions.
|
|
40
|
+
- **`204`, database record.** `XxxNotFound`, `NotAllowedToXxx`, `CurrentXxxIsSameAsTheNewOne`.
|
|
41
|
+
Thrown from inside the transaction callback ([transaction.md](./transaction.md)).
|
|
42
|
+
- **`202`, access right.** A credential that does not match, a principal barred from what it asked
|
|
43
|
+
for — `InvalidCredentials` and the like.
|
|
47
44
|
|
|
48
45
|
- **Name = the reason, not the field alone.** `InvalidPublishedAt`, `TagNotFound`,
|
|
49
46
|
`NotAllowedToEditArticle` — read as a sentence at the throw site. No `info`/`data`/`error`
|
|
@@ -169,11 +169,10 @@ static get errorCodeHash () {
|
|
|
169
169
|
}
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
- **
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
errors within this resolver. Keep a given resolver on one identifier and add sequentially.
|
|
172
|
+
- **The code's shape and its categories are settled by `hoc-error-codes`.** What a query resolver
|
|
173
|
+
decides is which category each of its own errors takes: `203` for what the validator rejects,
|
|
174
|
+
`204` for what the database does not hold. The framework's own codes are declared by the engine
|
|
175
|
+
below, and are never redeclared here.
|
|
177
176
|
- **Input-shape errors** (`InvalidXxx`) are raised by the validator via the shared `errorHash`, so
|
|
178
177
|
their names must exist here. **Domain errors** (`XxxNotFound`, `NoXxxFound`) are thrown from
|
|
179
178
|
`resolve()` with `this.errorHash.Xxx.create()` (optionally through a `createXxxError()` helper).
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Errors, context, and actual-vs-stub
|
|
2
2
|
|
|
3
|
-
The
|
|
4
|
-
auth and injected providers off `context`, and the actual-vs-stub split.
|
|
5
|
-
[SKILL.md](../SKILL.md).
|
|
3
|
+
The categories a query resolver's codes take, the validator↔errorHash contract, domain-error
|
|
4
|
+
creators, reading auth and injected providers off `context`, and the actual-vs-stub split.
|
|
5
|
+
Referenced from §1 and §4 of [SKILL.md](../SKILL.md).
|
|
6
6
|
|
|
7
7
|
> The `users` / `User` / `Department` names and the `Q001` / `Q002` identifiers are placeholders —
|
|
8
8
|
> swap in your resource and this resolver's own identifier.
|
|
9
9
|
|
|
10
|
-
## errorCodeHash:
|
|
10
|
+
## errorCodeHash: which category each error takes
|
|
11
11
|
|
|
12
12
|
`errorCodeHash` maps each error **name** to a **string code**; the framework's `create()` turns those
|
|
13
13
|
into the `this.errorHash.<Name>` constructors the resolver and its validator throw. Always spread
|
|
@@ -30,18 +30,14 @@ static get errorCodeHash () {
|
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
`101` concrete-member-not-found.
|
|
42
|
-
- **`<identifier>`** (`Q002`, …) is a **stable per-query id**. Keep one resolver on one identifier;
|
|
43
|
-
the letter tracks the endpoint family (`Q` for the query endpoints).
|
|
44
|
-
- **`<seq>`** (`001`, `002`, …) numbers the errors within this resolver, per family.
|
|
33
|
+
The code's shape, and the categories its leading digits sort a failure into, are settled by
|
|
34
|
+
`hoc-error-codes`. What a query resolver decides is which category each of its own errors takes:
|
|
35
|
+
|
|
36
|
+
- `203` — validational, raised by the `*InputValidator`.
|
|
37
|
+
- `204` — database record, thrown from `resolve()`.
|
|
38
|
+
|
|
39
|
+
The framework's own codes are already declared by the engine — `102` access right, `104` database
|
|
40
|
+
record, `100` unknown, `101` implementational — and a resolver never redeclares one.
|
|
45
41
|
|
|
46
42
|
## The validator ↔ errorHash contract
|
|
47
43
|
|
|
@@ -76,8 +76,8 @@ type). **LOW** = hardening gap. **INFO** = worth noting, not a vulnerability.
|
|
|
76
76
|
| 9 | Introspection / playground / debug endpoints disabled in prod | [auth-and-transport.md](./references/auth-and-transport.md) |
|
|
77
77
|
| 10 | CORS scoped (not wildcard in production) | [auth-and-transport.md](./references/auth-and-transport.md) |
|
|
78
78
|
| 11 | Rate limiting on public endpoints (and not bypassable) | [auth-and-transport.md](./references/auth-and-transport.md) |
|
|
79
|
-
| 12 |
|
|
80
|
-
| 13 |
|
|
79
|
+
| 12 | Production-facing env files covered by `.gitignore` | [secrets.md](./references/secrets.md) |
|
|
80
|
+
| 13 | Committed env files hold only values that reach the local machine | [secrets.md](./references/secrets.md) |
|
|
81
81
|
| 14 | No hardcoded secrets in code / config | [secrets.md](./references/secrets.md) |
|
|
82
82
|
| 15 | No plaintext passwords / secrets in seed / fixture data | [secrets.md](./references/secrets.md) |
|
|
83
83
|
| 16 | No vulnerable dependencies (advisory audit) | [dependencies.md](./references/dependencies.md) |
|
|
@@ -4,50 +4,65 @@
|
|
|
4
4
|
plaintext passwords in seed / fixture data. Referenced from [SKILL.md](../SKILL.md). **Mask every
|
|
5
5
|
secret value in the report.**
|
|
6
6
|
|
|
7
|
-
## 12.
|
|
7
|
+
## 12. Production-facing env files covered by `.gitignore`
|
|
8
|
+
|
|
9
|
+
Env files fall on two sides of one line, and the check differs by side.
|
|
10
|
+
|
|
11
|
+
| Side | Files | May be tracked |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| **production-facing** | `.env`, `.env.production`, `.env.prod`, `.env.staging` | never. `.env.staging` is shared with a client at times, so it is held as production |
|
|
14
|
+
| **local** | every other per-environment file — `.env.development`, `.env.live`, `.env.live-local`, `.env.test` and their like | yes, holding only values that reach the local machine (check 13) |
|
|
8
15
|
|
|
9
16
|
A `.gitignore` with a bare `.env` line matches **only** a file named exactly `.env` — it does **not**
|
|
10
|
-
match `.env.
|
|
11
|
-
|
|
17
|
+
match `.env.production`, `.env.staging` or `.env.prod`. Those stay trackable and are easily committed
|
|
18
|
+
with real secrets.
|
|
12
19
|
|
|
13
20
|
```bash
|
|
14
21
|
ls -a | grep -E '^\.env' # which env files exist on disk
|
|
15
22
|
git check-ignore -v .env .env.* 2>/dev/null # prints the matching rule for each IGNORED file
|
|
16
|
-
git ls-files | grep -E '(^|/)\.env' # env files TRACKED in git
|
|
23
|
+
git ls-files | grep -E '(^|/)\.env' # env files TRACKED in git — sort each onto its side
|
|
17
24
|
```
|
|
18
25
|
|
|
19
26
|
- **Important:** adding a pattern to `.gitignore` does **not** untrack a file that is already
|
|
20
|
-
committed — `.gitignore` only affects untracked files. If
|
|
21
|
-
removed from the index with `git rm --cached <file>` (and the secret rotated).
|
|
22
|
-
`git ls-files`, not just by reading `.gitignore`.
|
|
23
|
-
- **FINDING (HIGH if the tracked file holds real secrets, else MEDIUM):**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
committed — `.gitignore` only affects untracked files. If a production-facing env file is already
|
|
28
|
+
tracked, it must be removed from the index with `git rm --cached <file>` (and the secret rotated).
|
|
29
|
+
Verify with `git ls-files`, not just by reading `.gitignore`.
|
|
30
|
+
- **FINDING (HIGH if the tracked file holds real secrets, else MEDIUM):** a production-facing env file
|
|
31
|
+
is **tracked** or **not ignored**. Recommend ignoring each by name, `git rm --cached` for anything
|
|
32
|
+
already tracked, and — if a secret was ever committed — rotating it and purging history.
|
|
33
|
+
- **A local env file that is tracked is not a finding here.** Tracking it is allowed; what it holds
|
|
34
|
+
is judged in check 13.
|
|
35
|
+
- **PASS:** every production-facing env file is ignored and untracked.
|
|
36
|
+
|
|
37
|
+
## 13. Committed env files hold only values that reach the local machine
|
|
38
|
+
|
|
39
|
+
A tracked local env file (check 12) is allowed on a condition, so **every one is read, every time** —
|
|
40
|
+
this check is never skipped, and never answered from the file's name. Read each file, and report
|
|
41
|
+
values **masked**: whether a value is local is judged on its shape, and the report never echoes it.
|
|
42
|
+
|
|
43
|
+
| Allowed in a local env file | A finding wherever it sits |
|
|
44
|
+
|---|---|
|
|
45
|
+
| an endpoint on `127.0.0.1` or `localhost` — `http://localhost:3000` included | an external host |
|
|
46
|
+
| a placeholder credential — `user` / `password` and their like | a real staging or production endpoint |
|
|
47
|
+
| the connection of a CI or test database (`live`) | a key-shaped value — an API key, a token, a private key |
|
|
34
48
|
|
|
35
49
|
```bash
|
|
36
|
-
# For each TRACKED env file (from check 12), list
|
|
50
|
+
# For each TRACKED local env file (from check 12), list every key, whether it holds a value MASKED:
|
|
37
51
|
git ls-files | grep -E '(^|/)\.env' | while read f; do echo "== $f =="; \
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
#
|
|
52
|
+
sed -E 's/=.+$/=****(masked)/' "$f"; done
|
|
53
|
+
# Hosts are the one value read in full, since locality is the point: any that is not local is a
|
|
54
|
+
# finding. Credentials inside a URL are masked first:
|
|
55
|
+
git ls-files | grep -E '(^|/)\.env' | xargs grep -nE '(HOST|URL|ENDPOINT|DSN)[A-Z_]*=' \
|
|
56
|
+
| sed -E 's#://[^@/]*@#://****@#' \
|
|
57
|
+
| grep -vE '=([a-z+]+://)?(\*\*\*\*@)?(127\.0\.0\.1|localhost)([:/]|$)'
|
|
41
58
|
```
|
|
42
59
|
|
|
43
|
-
- **
|
|
44
|
-
|
|
45
|
-
- **
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- **PASS:** values are empty / obvious placeholders (`your-key-here`, `changeme`, `xxxx`), and a
|
|
50
|
-
secret-free template exists.
|
|
60
|
+
- **An auditor told not to read env files reports this check as BLOCKED, never as passed.** The
|
|
61
|
+
allowance in check 12 rests on this reading; without it, nothing says the file stayed local.
|
|
62
|
+
- **FINDING (HIGH):** a tracked local env file holds a value outside the allowed column — an external
|
|
63
|
+
host, a real staging or production endpoint, a key-shaped value. Recommend moving the value to a
|
|
64
|
+
production-facing file or a secret manager, and rotating it if it was real.
|
|
65
|
+
- **PASS:** every tracked local env file holds only allowed values.
|
|
51
66
|
|
|
52
67
|
## 14. No hardcoded secrets in code / config
|
|
53
68
|
|
|
@@ -62,12 +77,23 @@ git grep -nE "AIza[0-9A-Za-z_-]{20,}|sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|AK
|
|
|
62
77
|
```
|
|
63
78
|
|
|
64
79
|
- **Pay special attention to connection / datastore config files** — per-environment blocks commonly
|
|
65
|
-
carry hardcoded `username` / `password`.
|
|
66
|
-
finding
|
|
67
|
-
|
|
68
|
-
- **
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
carry hardcoded `username` / `password`. **A production or staging block takes its credentials from
|
|
81
|
+
the environment**, and a literal there is a finding even if it looks like a placeholder, because
|
|
82
|
+
it normalizes the pattern where it does harm.
|
|
83
|
+
- **The same line as check 13 holds outside env files.** A placeholder credential is not a finding
|
|
84
|
+
where only the local machine is reached by it:
|
|
85
|
+
|
|
86
|
+
| Not a finding | Why |
|
|
87
|
+
|---|---|
|
|
88
|
+
| the compose of local middleware whose ports are published on `127.0.0.1` only | nothing off the machine reaches it |
|
|
89
|
+
| the config of a CI or test database | it holds test data, and is rebuilt from nothing |
|
|
90
|
+
|
|
91
|
+
A port published on every interface (`3306:3306`, `0.0.0.0:…`) takes the compose out of the first
|
|
92
|
+
row, and its credentials are a finding again.
|
|
93
|
+
- **FINDING (HIGH real / MEDIUM placeholder):** a literal credential in tracked code / config, outside
|
|
94
|
+
the two rows above. Recommend sourcing from env / a secret manager; rotate if real.
|
|
95
|
+
- **PASS:** credentials come from `process.env` / a config facade, or are placeholders where only the
|
|
96
|
+
local machine reaches them.
|
|
71
97
|
|
|
72
98
|
## 15. No plaintext passwords / secrets in seed / fixture data
|
|
73
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openreachtech/hora-skills-ort-renchan",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Distributes the renchan backend skills used to develop with Hora Kit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -53,6 +53,9 @@
|
|
|
53
53
|
},
|
|
54
54
|
"overrides": {
|
|
55
55
|
"@humanfs/node": "^0.16.8",
|
|
56
|
+
"@istanbuljs/load-nyc-config": {
|
|
57
|
+
"js-yaml": "^4.3.2"
|
|
58
|
+
},
|
|
56
59
|
"brace-expansion@1": "^1.1.21",
|
|
57
60
|
"brace-expansion@5": "^5.0.12",
|
|
58
61
|
"flatted": "^3.4.4"
|