Repository navigation
fix(java,kotlin): read the credential key from Jackson's contract so a naming strategy cannot leak it - #601
Merged
Merged
Conversation
…a naming strategy cannot leak it The generated Spring controllers (codegen-spring, codegen-kotlin) hid a credential (a view.password field) by serializing the row to a JSON tree and removing the key spelled with the field name. Under a SNAKE_CASE or KEBAB_CASE Jackson naming strategy the key is pin_hash / pin-hash, the removal found nothing, and the credential was sent in every response. Released Java and Kotlin 8.2.0 to 8.2.3 are affected. The shared redact helper now: - reads each credential's wire key from the mapper's serialization contract (introspect().findProperties(), matched on the internal name), cached per row class, so a naming strategy, mixin or @JsonProperty is honoured; - fails closed: a row whose serializer is not a bean serializer, or whose class declares the credential with no matching (and not ignored) property, is refused, not sent; - also removes any key spelling the credential ignoring case, '_' and '-'. Every response path (list, get, create/update echo, M:N, TPH, projection, report JSON) already goes through the helper; the Kotlin M:N traversal now uses it too. The report CSV/XML exports write a fixed column list without credentials and never touch Jackson. The Java and Kotlin secret-fields generated-controller lanes gain a none/snake/kebab naming parameter over list, get-by-id and an inheriting projection (the Kotlin harness gains the projection); both leak under snake and kebab without the fix.
…osed behaviour tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
ObjectMapper's own serialization contract (SerializationConfig.introspect(...).findProperties(), matched on the property's internal name, cached per row class), so a naming strategy (SNAKE_CASE/KEBAB_CASE), mixin or@JsonPropertyrename can no longer leave the credential in the response; a second pass also removes any key spelling a credential ignoring case,_and-. Every redaction site (get, list, create/update echo, M:N traversal, TPH, projection, report) routes through the shared helper.secret-fieldsgenerated-controller conformance lanes gained anone/snake/kebabnaming-strategy parameter plus mixin-rename and custom-serializer fail-closed tests over embedded Tomcat (seeding made naming-independent); the harnesses accept a naming strategy and mapper customizer.CHANGELOG.mddocuments the leak for released 8.2.0–8.2.3, and the secret-fields corpus README states redaction is naming-strategy independent.Validation
Risk Assessment
✅ Low: Well-bounded security fix whose generated helpers fail closed, verified by behavior tests with independent seed-value oracles across both JVM ports; the fix-round code matches the recorded round-1 decision exactly and introduces no unrequired machinery.
Testing
Drove the credential-redaction fix end-to-end on both changed ports: each conformance test runs the real codegen-spring / codegen-kotlin generator on the secret-fields corpus, compiles the emitted controller with javac/Kotlin compiler, hosts it over embedded Tomcat, and exchanges real HTTP requests. Java lane 8/8 green, Kotlin lane 7/7 green. Naming-strategy cases (default, SNAKE_CASE, KEBAB_CASE) confirm pinHash is absent from entity list/get and the inheriting projection's routes while tokenHash is still returned under the strategy's own key (snake/kebab spelled), proving redaction keys off the mapper's contract, not the field name. Adversarial cases confirm the review-round fixes: a @JsonProperty mixin renaming the credential to "secret" still strips it, and a custom bean-less serializer makes the controller refuse the response with 500 ("cannot strip the credential ... the response is refused rather than sent unstripped") with no credential value in any body. Baseline broad regression came from the configured command scripts/ci-local.sh --affected --strict-toolchains, which passed at this target commit; I did not rerun it. No stray processes or temp dirs left behind.
Evidence: Java generated-controller secret-fields conformance (surefire)
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0 -- SecretFieldsGeneratedApiContractConformanceTestEvidence: Kotlin generated-controller secret-fields conformance (surefire)
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0 -- SecretFieldsGeneratedApiContractConformanceTestEvidence: Java fail-closed 500 under custom serializer (embedded Tomcat log)
IllegalStateException: cannot strip the credential AccountDto.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.Evidence: Kotlin fail-closed 500 under custom serializer (embedded Tomcat log)
IllegalStateException: cannot strip the credential Account.pinHash from a response: its serializer is not a bean serializer (a custom serializer?). Credential stripping reads the ObjectMapper's serialization contract; the response is refused rather than sent unstripped.Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringSecretFieldsCodegenTest.java:90- New codegen unit tests assert only that the emitted controller text contains implementation tokens (config.introspect(objectMapper.constructType(type)),p.getInternalName().equals(name),throw unstrippable(,key.replace("_", "")...). Matching text is a proxy for behavior: it passes if the code is dead or the fix is refactored, and it would still pass if the helper were wrong. Behavior is already proven by the none/snake/kebab integration lanes, so these add no independent evidence. Same pattern in the Kotlin twin: KotlinSecretFieldsTest.ktthe credential key is read from the mapper's contract...(about line 55). Remove both, or replace with a compile-and-run test that covers what the lanes do not: fail-closed (a custom serializer or missing property must throw), @JsonProperty/mixin rename, and the second-line-of-defence key removal. The pre-existingcontains(...)updates in KotlinSecretFieldsTest and KotlinReportCredentialTest only track the renamed emitted call and are the same existing style.🔧 Fix applied.
1 warning still open:
server/java/codegen-spring/src/test/java/com/metaobjects/generator/spring/SpringSecretFieldsCodegenTest.java:90- New codegen unit tests assert only that the emitted controller text contains implementation tokens (config.introspect(objectMapper.constructType(type)),p.getInternalName().equals(name),throw unstrippable(,key.replace("_", "")...). Matching text is a proxy for behavior: it passes if the code is dead or the fix is refactored, and it would still pass if the helper were wrong. Behavior is already proven by the none/snake/kebab integration lanes, so these add no independent evidence. Same pattern in the Kotlin twin: KotlinSecretFieldsTest.ktthe credential key is read from the mapper's contract...(about line 55). Remove both, or replace with a compile-and-run test that covers what the lanes do not: fail-closed (a custom serializer or missing property must throw), @JsonProperty/mixin rename, and the second-line-of-defence key removal. The pre-existingcontains(...)updates in KotlinSecretFieldsTest and KotlinReportCredentialTest only track the renamed emitted call and are the same existing style.✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --affected --strict-toolchainsmvn -f server/java/integration-tests/pom.xml test -Dtest=SecretFieldsGeneratedApiContractConformanceTest (8 tests: corpus scenarios, projection inheritance, naming none/snake/kebab, mixin rename, custom-serializer fail-closed)mvn -f server/java/integration-tests-kotlin/pom.xml test -Dtest=SecretFieldsGeneratedApiContractConformanceTest (7 tests: same matrix on the Kotlin generator)Baseline broad regression: scripts/ci-local.sh --affected --strict-toolchains already passed at target commit c75e4166a✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.