Summary
Jervis, a library for Job DSL plugin scripts and shared Jenkins pipeline libraries, contained a cryptographic implementation error where SHA-256 digests were padded to only 32 characters instead of the required 64 hex characters.
Under conditions where this incorrectly padded hash is used as an integrity check, token, or signature component, an attacker could exploit the truncated value to weaken security guarantees, potentially bypassing validation or reducing the effective search space of the hash.
Affected context
The issue affects environments that:
- Use Jervis prior to version 2.2
- Rely on Jervis to compute or compare SHA-256-based values (e.g., identifiers, checksums, or signatures)
- Treat the resulting hex-encoded hash as a security-relevant artifact (for integrity, authenticity, or uniqueness)
In these contexts, only 32 hex characters are produced for SHA-256 digests instead of the full 64, reducing the effective representation of the hash and potentially undermining assumptions about its strength.
Exploit preconditions
- Attack surface: Any workflow, pipeline, or script that consumes Jervis-generated SHA-256 hex strings for security decisions (such as validation, gating, or trust checks).
- Required access: Ability to influence or observe inputs whose hashes are computed by Jervis, or to supply alternative values to collide under the truncated representation.
- Trigger point: Operations that compute, store, or compare SHA-256 digests using Jervis's padding logic, particularly when the truncated value is used as a security control.
- Why exploitation is possible: The implementation pads SHA-256 digests to 32 hex characters instead of 64, effectively truncating the digest representation and weakening the space an attacker must search to find values that produce the same truncated output.
Why this happens
The root cause is an incorrect assumption about the size of a SHA-256 hash when rendered in hexadecimal form. SHA-256 yields 32 bytes, which must be represented as 64 hex characters; using padLeft(32, '0') instead of padLeft(64, '0') results in an under-sized hex string.
This maps to CWE-327: Use of a Broken or Risky Cryptographic Algorithm, in the sense that the cryptographic construction is misapplied. While SHA-256 itself is sound, the faulty encoding truncates its effective representation, degrading its intended security properties. Abstractly, this is a cryptographic implementation error where formatting/encoding logic fails to preserve the full entropy of the underlying digest.
Potential impact
- Reduction of the effective hash space, which can lower the work factor required to find inputs that collide under the truncated hash representation
- Possible bypass of integrity checks if systems trust the truncated value as a full-strength SHA-256 digest
- Increased risk of accidental or malicious collisions where distinct inputs share the same truncated hash
- Undermined auditability or traceability if hashes are used as unique identifiers, leading to ambiguity in logs or artifact metadata
General mitigation guidance
Mitigation typically focuses on ensuring that cryptographic values are correctly represented and validated end-to-end:
- Verify that all SHA-256 digests are represented with the full 64-character hexadecimal encoding, preserving the complete 32-byte output.
- Treat formatting and encoding logic for cryptographic outputs as security-sensitive and subject to the same rigor as the core cryptographic routines.
- Implement automated tests that assert expected length and format of cryptographic values (for example, asserting that a SHA-256 hex string is exactly 64 characters).
- Where hashes are used as identifiers or verification tokens, consider adding explicit schema or contract checks that reject malformed or truncated values.
- Apply a defense-in-depth approach by not relying solely on a single hash comparison for critical authorization or integrity controls.
How teams detect issues like this
Organizations can detect and prevent similar issues through:
- Static analysis and linting: Rules that flag fixed-size hash encodings with incorrect lengths (e.g., SHA-256 represented with anything other than 64 hex characters).
- Code review practices: Explicit review of cryptographic usage, including key sizes, hash lengths, and encoding details, treating these as high-risk areas requiring reviewer acknowledgment.
- Unit and integration tests: Test fixtures that compare known SHA-256 test vectors against implementation outputs, verifying both content and length.
- Policy enforcement in CI: Security gates that run automated cryptographic correctness tests or SAST tools on pull requests, particularly for libraries used in build and deployment pipelines like Jervis.

