@mrciphersmith/keryx 0.4.29 → 0.4.30
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/cli.js +2408 -1369
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,67 +7,50 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Go security
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`' stack-agnostic security rules to Go-specific
|
|
11
|
-
OWASP
|
|
12
|
-
|
|
10
|
+
Narrows `core-common-rules`' stack-agnostic security rules to Go-specific
|
|
11
|
+
risks (OWASP) and the safe standard-library API. Applies only to `*.go`
|
|
12
|
+
files.
|
|
13
13
|
|
|
14
14
|
## Command and shell execution
|
|
15
15
|
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- When a shell really is required (globbing, pipelines), validate/allowlist
|
|
21
|
-
every piece of untrusted input that reaches the string before it is
|
|
22
|
-
built, and say so in the change.
|
|
16
|
+
- Use `os/exec.Command(name, args...)`; never interpolate untrusted input
|
|
17
|
+
into `exec.Command("sh", "-c", cmd)`.
|
|
18
|
+
- When a shell is required (globbing, pipelines), allowlist every piece of
|
|
19
|
+
untrusted input that reaches the string, and say so in the change.
|
|
23
20
|
|
|
24
21
|
## Templating and output encoding
|
|
25
22
|
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
escaping and is an XSS vector the moment its output reaches a browser;
|
|
29
|
-
reserve `text/template` for genuinely non-HTML output (config files,
|
|
30
|
-
emails in plain text).
|
|
23
|
+
- `html/template` for any HTML/JS/CSS/URL output; `text/template` only for
|
|
24
|
+
non-HTML output (config files, plain-text email).
|
|
31
25
|
|
|
32
26
|
## SQL and data access
|
|
33
27
|
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- An ORM/query builder's raw-SQL escape hatch carries the same rule: pass
|
|
39
|
-
parameters through its placeholder API, not through interpolated
|
|
40
|
-
strings.
|
|
28
|
+
- `database/sql` placeholders (`?` or `$1`), never `fmt.Sprintf` or
|
|
29
|
+
concatenation with a user-influenced value.
|
|
30
|
+
- The same for an ORM/query builder's raw-SQL escape hatch: use its
|
|
31
|
+
placeholder API.
|
|
41
32
|
|
|
42
33
|
## Randomness and secrets
|
|
43
34
|
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
load it from environment/secret storage the project already uses.
|
|
35
|
+
- `crypto/rand` for tokens, session IDs, keys, nonces; never
|
|
36
|
+
`math/rand`/`math/rand/v2`.
|
|
37
|
+
- No hard-coded credential, API key, or signing secret; load from the
|
|
38
|
+
environment/secret storage the project already uses.
|
|
49
39
|
|
|
50
40
|
## Filesystem and path handling
|
|
51
41
|
|
|
52
|
-
- `filepath.Clean`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
untrusted relative path, prefer `os.Root` (Go 1.24+) or
|
|
56
|
-
`filepath.IsLocal` to confirm containment before opening, rather than
|
|
57
|
-
`filepath.Clean` alone.
|
|
42
|
+
- `filepath.Clean` alone does not contain a path. For opening files under a
|
|
43
|
+
fixed root from an untrusted relative path, use `os.Root` (Go 1.24+) or
|
|
44
|
+
`filepath.IsLocal`.
|
|
58
45
|
|
|
59
46
|
## TLS and network
|
|
60
47
|
|
|
61
|
-
- Never
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
typically `ReadTimeout`/`WriteTimeout`/`IdleTimeout`); a server with no
|
|
66
|
-
timeouts is vulnerable to slow-client resource exhaustion (Slowloris).
|
|
48
|
+
- Never `InsecureSkipVerify: true` outside a short-lived local test, never
|
|
49
|
+
shipped.
|
|
50
|
+
- `http.Server` with explicit `ReadHeaderTimeout` (and typically
|
|
51
|
+
`ReadTimeout`/`WriteTimeout`/`IdleTimeout`).
|
|
67
52
|
|
|
68
53
|
## Dependency hygiene
|
|
69
54
|
|
|
70
|
-
- Run `govulncheck ./...` when introducing or updating dependencies, or
|
|
71
|
-
|
|
72
|
-
the Go vulnerability database against actually-reachable code paths,
|
|
73
|
-
not just declared dependency versions.
|
|
55
|
+
- Run `govulncheck ./...` when introducing or updating dependencies, or when
|
|
56
|
+
asked to check a module for known vulnerabilities.
|
|
@@ -13,56 +13,38 @@ Narrows `core-common-rules`' stack-agnostic testing rules to the standard
|
|
|
13
13
|
|
|
14
14
|
## Layout and naming
|
|
15
15
|
|
|
16
|
-
- Tests live beside the code
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Table-driven tests with `t.Run(tc.name,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
already excludes it from builds — do not invent another fixture
|
|
24
|
-
directory convention.
|
|
16
|
+
- Tests live beside the code as `<file>_test.go` in the same package (or
|
|
17
|
+
`<pkg>_test` for black-box tests of the exported API); no separate `tests/`
|
|
18
|
+
tree.
|
|
19
|
+
- Table-driven tests with `t.Run(tc.name, ...)` for more than one case; name
|
|
20
|
+
cases descriptively, not `case1`/`case2`.
|
|
21
|
+
- `testdata/` for golden files and fixtures; no other fixture directory
|
|
22
|
+
convention.
|
|
25
23
|
|
|
26
24
|
## Test helpers and lifecycle
|
|
27
25
|
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
`t.Run` and parallel subtests.
|
|
33
|
-
- Use `t.Context()` (Go 1.24+) for a context that is canceled when the
|
|
34
|
-
test completes, instead of hand-rolling `context.WithCancel` plus a
|
|
35
|
-
`defer cancel()` in every test.
|
|
36
|
-
- Call `t.Parallel()` deliberately, only when the subtest's fixtures are
|
|
37
|
-
genuinely independent — a parallel subtest sharing mutable fixture
|
|
38
|
-
state races silently.
|
|
26
|
+
- `t.Helper()` as the first line of a helper.
|
|
27
|
+
- `t.Cleanup` for teardown instead of a scattered `defer` chain.
|
|
28
|
+
- `t.Context()` (Go 1.24+) instead of hand-rolled `context.WithCancel`.
|
|
29
|
+
- `t.Parallel()` only when the subtest's fixtures are independent.
|
|
39
30
|
|
|
40
31
|
## Assertions and determinism
|
|
41
32
|
|
|
42
|
-
- Plain `if got != want { t.Errorf(...) }`
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
helper with a timeout so the test is deterministic and not flaky under
|
|
48
|
-
load.
|
|
49
|
-
- `httptest.NewServer`/`httptest.NewRecorder` for HTTP handler tests
|
|
50
|
-
instead of binding a real port.
|
|
33
|
+
- Plain `if got != want { t.Errorf(...) }` or the project's configured
|
|
34
|
+
assertion library; do not add a new one.
|
|
35
|
+
- Never `time.Sleep` to wait for async results; use a channel,
|
|
36
|
+
`sync.WaitGroup`, `context` deadline, or a polling helper with a timeout.
|
|
37
|
+
- `httptest.NewServer`/`httptest.NewRecorder` for HTTP handler tests.
|
|
51
38
|
|
|
52
39
|
## Fuzzing and benchmarks
|
|
53
40
|
|
|
54
|
-
- `func FuzzX(f *testing.F)` with `f.Add(...)`
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- Benchmarks use `for b.Loop() { ... }` (Go 1.24+)
|
|
58
|
-
`for i := 0; i < b.N; i
|
|
59
|
-
and keeps loop-body values alive against dead-code elimination, so
|
|
60
|
-
results are not accidentally optimized away.
|
|
41
|
+
- `func FuzzX(f *testing.F)` with `f.Add(...)` seeds for parsers, decoders,
|
|
42
|
+
and untrusted input formats; run `go test -fuzz=FuzzX` locally before
|
|
43
|
+
relying on it in CI.
|
|
44
|
+
- Benchmarks use `for b.Loop() { ... }` (Go 1.24+), not
|
|
45
|
+
`for i := 0; i < b.N; i++`.
|
|
61
46
|
|
|
62
47
|
## Race detection and coverage
|
|
63
48
|
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
assertions cannot see.
|
|
67
|
-
- New behavior gets a new test in the same change; a bug fix gets a
|
|
68
|
-
regression test that fails before the fix and passes after.
|
|
49
|
+
- `go test -race ./...` for any change touching goroutines, shared state, or
|
|
50
|
+
channels.
|
|
@@ -9,59 +9,40 @@ metadata:
|
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic style rules to current Spring
|
|
11
11
|
Boot 3.x idiom, for both Java and Kotlin sources. Applies only to
|
|
12
|
-
`*.java`/`*.kt`/`*.kts` files
|
|
13
|
-
still comes from the common rules this file `extends`.
|
|
12
|
+
`*.java`/`*.kt`/`*.kts` files.
|
|
14
13
|
|
|
15
14
|
## Dependency injection
|
|
16
15
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
constructor
|
|
20
|
-
|
|
21
|
-
properties. Field-level `@Autowired` is discouraged — it hides the
|
|
22
|
-
dependency graph, prevents the field from being `final`/`val`, and
|
|
23
|
-
makes the class impossible to construct without the Spring container in
|
|
24
|
-
a plain unit test.
|
|
16
|
+
- Constructor injection over field injection: a Java `@Service` declares
|
|
17
|
+
`private final` fields set in the constructor (no `@Autowired` on a sole
|
|
18
|
+
constructor); a Kotlin class declares constructor `val` properties.
|
|
19
|
+
Field-level `@Autowired` is discouraged.
|
|
25
20
|
- Overrides the `solid-principles.mdc` "Constructor dependencies" row
|
|
26
21
|
for Java/Kotlin: more than 4 is the threshold, a signal of too many
|
|
27
22
|
responsibilities, never a reason to fall back to field injection.
|
|
28
23
|
|
|
29
24
|
## Layered architecture
|
|
30
25
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
HTTP concerns in a service.
|
|
37
|
-
- Expose a request/response DTO at the API boundary, never a JPA `@Entity`
|
|
38
|
-
directly — an entity carries lazy associations and persistence-specific
|
|
39
|
-
fields that leak internal structure and can trigger
|
|
40
|
-
`LazyInitializationException` when serialized outside a transaction.
|
|
26
|
+
- Controller/service/repository layers stay distinct: a `@RestController`
|
|
27
|
+
parses/validates the request and delegates to a `@Service`; business logic
|
|
28
|
+
and transaction boundaries live in the service; a `@Repository`/Spring Data
|
|
29
|
+
interface is the only layer that talks to persistence.
|
|
30
|
+
- Expose a request/response DTO at the API boundary, never a JPA `@Entity`.
|
|
41
31
|
|
|
42
32
|
## Naming and structure
|
|
43
33
|
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
- Kotlin:
|
|
47
|
-
|
|
48
|
-
with manually written `equals`/`hashCode`/`toString`.
|
|
49
|
-
- Kotlin null-safety: model an optional field as a nullable type (`String?`)
|
|
50
|
-
and handle it with `?.`/`?:`/`requireNotNull`, not `!!` — a `!!` on
|
|
51
|
-
anything that can plausibly be null at runtime (a request field, a
|
|
52
|
-
lookup result) reintroduces the NPE the type system exists to prevent.
|
|
34
|
+
- Kotlin: a `data class` for a DTO/value-holder, not a plain class with
|
|
35
|
+
hand-written `equals`/`hashCode`/`toString`.
|
|
36
|
+
- Kotlin null-safety: an optional field is a nullable type (`String?`)
|
|
37
|
+
handled with `?.`/`?:`/`requireNotNull`, not `!!`.
|
|
53
38
|
|
|
54
39
|
## Bean Validation and DTOs
|
|
55
40
|
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
DTO at the boundary, not re-implemented as manual `if` checks inside
|
|
60
|
-
the service.
|
|
41
|
+
- `jakarta.validation` constraints (`@NotNull`, `@NotBlank`, `@Size`,
|
|
42
|
+
`@Email`) on request DTO fields and `@Valid`/`@Validated` on the controller
|
|
43
|
+
parameter, not manual `if` checks in the service.
|
|
61
44
|
|
|
62
45
|
## Formatting
|
|
63
46
|
|
|
64
47
|
- Follow the project's configured formatter (`spotless`, `ktlint`,
|
|
65
|
-
google-java-format
|
|
66
|
-
wires up) rather than hand-formatting around it; do not introduce a
|
|
67
|
-
second formatter into a project that has already standardized on one.
|
|
48
|
+
google-java-format); do not add a second one.
|
|
@@ -8,58 +8,41 @@ metadata:
|
|
|
8
8
|
# Java/Kotlin + Spring patterns
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic design guidance to idiomatic
|
|
11
|
-
Spring Boot 3.x design
|
|
12
|
-
|
|
11
|
+
Spring Boot 3.x design, for both Java and Kotlin. Applies only to
|
|
12
|
+
`*.java`/`*.kt`/`*.kts` files.
|
|
13
13
|
|
|
14
14
|
## Transaction boundaries and the self-invocation pitfall
|
|
15
15
|
|
|
16
|
-
- `@Transactional`
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
bean the caller depends on (constructor-injected), so the call crosses
|
|
24
|
-
a real proxy boundary, instead of calling `this.otherTransactionalMethod()`.
|
|
25
|
-
- Keep a `@Transactional` method free of unrelated I/O (HTTP calls,
|
|
26
|
-
file access) that would hold the transaction/connection open longer
|
|
27
|
-
than necessary.
|
|
16
|
+
- `@Transactional` on the outermost service method that defines the unit of
|
|
17
|
+
work, not on every repository call.
|
|
18
|
+
- A call to another `@Transactional` method on the same class through `this`
|
|
19
|
+
bypasses the proxy and the annotation is ignored. Move the method to a
|
|
20
|
+
separate constructor-injected bean.
|
|
21
|
+
- No unrelated I/O (HTTP calls, file access) inside a `@Transactional`
|
|
22
|
+
method.
|
|
28
23
|
|
|
29
24
|
## Spring Data JPA query patterns
|
|
30
25
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- Prefer a derived query method or `@Query` with named parameters over
|
|
38
|
-
building JPQL/native SQL by string concatenation.
|
|
39
|
-
- Use a projection (an interface or DTO) for a read path that only needs
|
|
40
|
-
a subset of an entity's fields, instead of loading the full entity
|
|
41
|
-
graph and mapping it down in the service layer.
|
|
26
|
+
- N+1 on lazy associations: fix with `@EntityGraph`, JPQL `JOIN FETCH`, or a
|
|
27
|
+
projection; no blanket `FetchType.EAGER`.
|
|
28
|
+
- A derived query method or `@Query` with named parameters over
|
|
29
|
+
string-concatenated JPQL/native SQL.
|
|
30
|
+
- A projection (interface or DTO) for a read path needing a subset of an
|
|
31
|
+
entity's fields.
|
|
42
32
|
|
|
43
33
|
## Dependency injection and bean design
|
|
44
34
|
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
gives a test the same seam via a test double.
|
|
51
|
-
- Favor constructor injection producing an immutable, fully-initialized
|
|
52
|
-
bean over setter injection or field injection, which both allow a bean
|
|
53
|
-
to exist in a partially-configured state.
|
|
35
|
+
- An interface at the consumer boundary only when a component has more than
|
|
36
|
+
one implementation or must be mocked across module boundaries; none for a
|
|
37
|
+
single Spring-managed implementation "for testability".
|
|
38
|
+
- Constructor injection producing an immutable, fully-initialized bean over
|
|
39
|
+
setter or field injection.
|
|
54
40
|
|
|
55
41
|
## Anti-patterns to flag
|
|
56
42
|
|
|
57
|
-
- A "god service"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
response.
|
|
64
|
-
- A `@RestController` method containing business/query logic directly
|
|
65
|
-
instead of delegating to a service — controllers should stay thin.
|
|
43
|
+
- A "god service" accumulating unrelated business logic across domains.
|
|
44
|
+
- Catching a broad `Exception`/`RuntimeException` in a service only to log
|
|
45
|
+
and swallow it, instead of propagating to a `@ControllerAdvice`/
|
|
46
|
+
`@ExceptionHandler`.
|
|
47
|
+
- A `@RestController` method containing business/query logic instead of
|
|
48
|
+
delegating to a service.
|
|
@@ -8,62 +8,50 @@ metadata:
|
|
|
8
8
|
# Java/Kotlin + Spring security
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic security rules to Spring Boot
|
|
11
|
-
3.x-specific
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
3.x-specific risks (OWASP). Broadly scoped to all Java/Kotlin sources for
|
|
12
|
+
data-access and secrets guidance, with extra emphasis on controller and
|
|
13
|
+
security-config files for the HTTP-facing rules.
|
|
14
14
|
|
|
15
15
|
## Spring Security configuration
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
major version.
|
|
23
|
-
- Scope authorization rules explicitly (`authorizeHttpRequests` with
|
|
24
|
-
path/role matchers) rather than leaving a catch-all `permitAll()` that
|
|
25
|
-
was only meant for one endpoint during development.
|
|
17
|
+
- A `SecurityFilterChain` `@Bean` from a `@Configuration` class
|
|
18
|
+
(`http.build()`); never extend `WebSecurityConfigurerAdapter` (removed in
|
|
19
|
+
Spring Security 6 / Spring Boot 3).
|
|
20
|
+
- Scope authorization explicitly (`authorizeHttpRequests` with path/role
|
|
21
|
+
matchers); no catch-all `permitAll()` left from one development endpoint.
|
|
26
22
|
|
|
27
23
|
## CSRF
|
|
28
24
|
|
|
29
25
|
- A stateless, token-authenticated API (bearer JWT/OAuth2, no session
|
|
30
|
-
cookie)
|
|
31
|
-
|
|
32
|
-
state this reasoning explicitly when disabling it.
|
|
26
|
+
cookie) may disable CSRF (`csrf(AbstractHttpConfigurer::disable)`); state
|
|
27
|
+
the reason when disabling it.
|
|
33
28
|
- A session-cookie-authenticated endpoint (browser form login, `JSESSIONID`)
|
|
34
|
-
|
|
35
|
-
attack the stateless-API exception does not apply to.
|
|
29
|
+
keeps CSRF protection enabled.
|
|
36
30
|
|
|
37
31
|
## SQL and data access
|
|
38
32
|
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- The same applies to `JdbcTemplate`/`NamedParameterJdbcTemplate`: use its
|
|
45
|
-
parameter-binding API, never interpolate a value into the SQL string.
|
|
33
|
+
- Spring Data JPA derived queries or parameterized `@Query` (named or
|
|
34
|
+
positional bind parameters); never string-concatenated or
|
|
35
|
+
`String.format`-built SQL/JPQL with a user-influenced value.
|
|
36
|
+
- `JdbcTemplate`/`NamedParameterJdbcTemplate` through its parameter-binding
|
|
37
|
+
API, never interpolation into the SQL string.
|
|
46
38
|
|
|
47
39
|
## Input validation as the DTO boundary defense
|
|
48
40
|
|
|
49
41
|
- Validate untrusted input at the DTO boundary with `jakarta.validation`
|
|
50
|
-
annotations plus `@Valid`/`@Validated` on the controller method
|
|
51
|
-
|
|
52
|
-
data, on top of (not instead of) parameterized queries downstream.
|
|
42
|
+
annotations plus `@Valid`/`@Validated` on the controller method, in
|
|
43
|
+
addition to parameterized queries downstream.
|
|
53
44
|
|
|
54
45
|
## Secrets and configuration
|
|
55
46
|
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
- Do not log a request/response body that may carry credentials, tokens,
|
|
62
|
-
or PII at `INFO`/`DEBUG` level without redaction.
|
|
47
|
+
- No hard-coded credential, API key, or signing secret in source or in
|
|
48
|
+
committed `application.yml`/`application.properties`; use environment
|
|
49
|
+
variables, a config server, or the project's secret store.
|
|
50
|
+
- Do not log a request/response body that may carry credentials, tokens, or
|
|
51
|
+
PII at `INFO`/`DEBUG` without redaction.
|
|
63
52
|
|
|
64
53
|
## Dependency hygiene
|
|
65
54
|
|
|
66
55
|
- Run the project's configured dependency-vulnerability check (OWASP
|
|
67
|
-
Dependency-Check plugin, `./gradlew dependencyCheckAnalyze
|
|
68
|
-
|
|
69
|
-
dependency, rather than skipping it because "it's just a minor bump."
|
|
56
|
+
Dependency-Check plugin, `./gradlew dependencyCheckAnalyze`) when
|
|
57
|
+
introducing or bumping a dependency, including a minor bump.
|
|
@@ -13,68 +13,52 @@ Spring Boot Test conventions, for both Java and Kotlin. Applies only to
|
|
|
13
13
|
|
|
14
14
|
## Layout and naming
|
|
15
15
|
|
|
16
|
-
- Tests
|
|
17
|
-
|
|
18
|
-
`<Type>IT`/`<Type>IntegrationTest` (integration)
|
|
19
|
-
convention
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
integration coverage — a full context load per test class is slow and
|
|
24
|
-
is not a substitute for testing a service's logic in isolation.
|
|
16
|
+
- Tests under `src/test/java` or `src/test/kotlin`, mirroring the package of
|
|
17
|
+
the class under test, named `<Type>Test` (unit) or
|
|
18
|
+
`<Type>IT`/`<Type>IntegrationTest` (integration); match the project's
|
|
19
|
+
convention.
|
|
20
|
+
- A plain unit test (construct the class directly, pass mocks/fakes to the
|
|
21
|
+
constructor) for logic that does not need the Spring container;
|
|
22
|
+
`@SpringBootTest` only for genuine integration coverage.
|
|
25
23
|
|
|
26
24
|
## Test slices
|
|
27
25
|
|
|
28
|
-
-
|
|
29
|
-
`@
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Testcontainers over an in-memory substitute (H2 standing in for
|
|
34
|
-
Postgres/MySQL) when the project already uses Testcontainers — an
|
|
35
|
-
in-memory DB can silently pass a query that the real production
|
|
36
|
-
database would reject or execute differently.
|
|
26
|
+
- The narrowest Spring test slice: `@WebMvcTest` for a controller (with
|
|
27
|
+
`MockMvc`), `@DataJpaTest` for a repository, `@SpringBootTest` only when
|
|
28
|
+
the interaction across the whole wired context is under test.
|
|
29
|
+
- Testcontainers over an in-memory substitute (H2 standing in for
|
|
30
|
+
Postgres/MySQL) when the project already uses Testcontainers.
|
|
37
31
|
|
|
38
32
|
## Mocking
|
|
39
33
|
|
|
40
|
-
- Mock/stub only the collaborators the class under test
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Assert on behavior/interactions relevant to the test (`verify(...)`),
|
|
49
|
-
not on incidental implementation details that would make the test
|
|
50
|
-
brittle to a harmless refactor.
|
|
34
|
+
- Mock/stub only the collaborators the class under test depends on
|
|
35
|
+
(Mockito `@Mock`/`@InjectMocks`, or MockK for Kotlin); no
|
|
36
|
+
`@MockitoBean`/`@SpringBootTest` just to avoid constructing a plain
|
|
37
|
+
dependency by hand. `@MockitoBean` is the annotation for mocking a bean
|
|
38
|
+
inside a Spring test slice; `@MockBean` is deprecated since Boot 3.4 and
|
|
39
|
+
removed in 4.x, so use it only on a project pinned below 3.4.
|
|
40
|
+
- Assert on behavior/interactions relevant to the test (`verify(...)`), not
|
|
41
|
+
incidental implementation details.
|
|
51
42
|
|
|
52
43
|
## Assertions and determinism
|
|
53
44
|
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
is deterministic and not flaky under CI load.
|
|
61
|
-
- A test covering validation should assert on the specific constraint
|
|
62
|
-
violation/exception type, not just that "some" exception was thrown.
|
|
45
|
+
- The project's configured assertion library (AssertJ, JUnit's own, or
|
|
46
|
+
Kotlin's `kotlin.test`); do not add a second.
|
|
47
|
+
- Never `Thread.sleep`/`delay` to wait for an async result; use Awaitility
|
|
48
|
+
(`await().atMost(...).until(...)`), a `CompletableFuture`/coroutine join,
|
|
49
|
+
or a `CountDownLatch`.
|
|
50
|
+
- A validation test asserts the specific constraint violation/exception type.
|
|
63
51
|
|
|
64
52
|
## Fixtures and lifecycle
|
|
65
53
|
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
per-test setup/teardown; reserve `@BeforeAll`/`@AfterAll` for
|
|
72
|
-
genuinely expensive, safely-shared setup (a Testcontainers instance).
|
|
54
|
+
- A builder or test-fixture factory method with sensible defaults,
|
|
55
|
+
overriding only the fields the test cares about.
|
|
56
|
+
- `@BeforeEach`/`@AfterEach` for per-test setup/teardown; `@BeforeAll`/
|
|
57
|
+
`@AfterAll` only for expensive, safely-shared setup (a Testcontainers
|
|
58
|
+
instance).
|
|
73
59
|
|
|
74
60
|
## Coverage expectations
|
|
75
61
|
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for any change touching test files, and its integration-test task
|
|
80
|
-
separately when one is configured, before reporting done.
|
|
62
|
+
- Run the build-tool test task (`./gradlew test` or `mvn test`) for any
|
|
63
|
+
change touching test files, and the integration-test task separately when
|
|
64
|
+
configured, before reporting done.
|