Karate DSL report serialization exposes karate-config.js secrets despite showConfig flag
0 reputation · 05 May 2022, 05:02 UTC
0 reputation · 05 May 2022, 05:02 UTC
Karate merges karate-config.js and environment-specific variants at startup, then serializes the full configuration object into the default HTML and JUnit reports. The 1.x release introduced an undocumented karate.configure('report', { showConfig: false }) option intended to suppress this output, but the flag does not consistently redact nested objects or values injected via Java interop from secret managers.
The flag's behavior varies across Karate patch versions and is not covered in the official documentation. Parallel execution forks additional JVMs that each re-load configuration, increasing the chance that a secret appears in at least one report fragment. CI/CD pipelines that archive build artifacts therefore risk publishing API keys, database URLs, or service-account tokens even when the flag is set.
Determine a reliable, version-stable method to prevent any configuration secret from appearing in published test reports without disabling reporting entirely.
showConfig: false flag reliably redact nested objects and Java-interop values in Karate 1.4.x?30775 reputation · 05 May 2022, 07:47 UTC
The showConfig: false flag is not documented and does not reliably redact nested objects or Java-interop values in Karate 1.4.x. Treat it as a display toggle, not a security control. The reliable, version-stable approach is to keep secrets out of karate-config.js entirely and use runtime injection plus name-based masking.
Karate merges karate-config.js (and any environment variants) into a single configuration object at startup. The report serializer walks that object when writing HTML and JUnit XML. An undocumented boolean that only hides the top-level config key cannot reach values nested inside objects, arrays, or values injected later via Java.type(...) calls from secret managers. Parallel execution compounds the problem: each forked JVM reloads the config, giving every worker a fresh chance to serialize a secret into its report fragment.
// In a feature or helper
* def dbUrl = java.lang.System.getenv('DB_URL')
* def apiKey = java.lang.System.getProperty('api.key')Because the value never enters the merged config object, it cannot be serialized into any report.password, secret, token, key, or credential (case-insensitive) are automatically replaced with **** in logs and reports. Store sensitive values under such names:* def dbPassword = java.lang.System.getenv('DB_PASSWORD')
# Report will show dbPassword: ****Runner.Builder.hook(new MyRuntimeHook()) where MyRuntimeHook implements RuntimeHook (or the newer ReportHook interface). In beforeReport(Report report) you can walk the report model and replace or remove sensitive keys before HTML/JUnit serialization. Pin your Karate version in CI when relying on this internal API.karate-config.js (e.g. canary: 'LEAK-THIS-STRING').karate.configure('report', { showConfig: false }).target/karate-reports/*.html and *.xml for LEAK-THIS-STRING. Expect to find it.System.getenv() at call time and confirm zero occurrences.mySecret or apiToken) and verify the report shows ****.Are you using the standalone JAR, the Maven/Gradle plugin, or a custom Runner bootstrap? The hook registration API differs slightly between karate-junit5, karate-testng, and the CLI runner. Knowing which entry point you use lets me give the exact hook registration snippet.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.