← Back to Pull requests

MINOR: Use constant-time comparison for signed footer GCM tag #3655

Closed
unknown closed this pull request without merging on Oct 23, 2026 02:02 UTC
View on GitHub
unknown unknown commented on Jul 11, 2026 09:26 UTC
Author

Rationale for this change

When an encrypted file is written with a plaintext (signed) footer, the footer
carries an AES-GCM authentication tag. On read,
ParquetMetadataConverter.verifyFooterIntegrity recomputes the tag and compares
it against the stored one to detect tampering.

That comparison used java.util.Arrays.equals, which returns as soon as it hits
a mismatching byte, so its running time depends on how many leading bytes match.
Comparing a secret authentication tag this way is a timing side channel
(CWE-208): an attacker who can measure verification time over many crafted files
could, in principle, recover the correct tag byte by byte. Constant-time
comparison is the standard practice for MAC/authentication-tag checks.

What changes are included in this PR?

  • In ParquetMetadataConverter.verifyFooterIntegrity, replace

  • Arrays.equals(gcmTag, calculatedTag) with
    MessageDigest.isEqual(gcmTag, calculatedTag) and add
    import java.security.MessageDigest;. A short comment notes the CWE-208
    rationale. MessageDigest.isEqual has the same boolean contract (true iff both
    arrays are non-null, of equal length, and byte-for-byte equal) but is
    implemented to run in time independent of the number of matching bytes, so the
    change is behavior-preserving: tampered footers are still rejected with a
    TagVerificationException. (The Arrays import stays; it is used elsewhere in
    the file.)
  • Add TestFooterIntegrity in parquet-hadoop covering the signed

  • plaintext-footer path end to end: a valid signature is accepted, and a footer
    whose GCM tag has one byte flipped is rejected with TagVerificationException.

    The other Arrays.equals calls in the crypto module compare non-secret
    identifiers (AAD prefix, key-metadata reuse checks), not a secret MAC, so they
    are intentionally left unchanged.

    Are these changes tested?

    Yes.

  • mvn -pl parquet-hadoop -Dtest=TestFooterIntegrity test -> both cases pass.

  • The existing encryption suites still pass with the change:

  • mvn -pl parquet-hadoop -Dtest='ColumnEncryptorTest,TestPropertiesDrivenEncryption,TestFooterIntegrity' test
    -> 43 tests, 0 failures, 0 errors.
  • The negative test was confirmed to be meaningful: temporarily neutralizing the

  • tag check makes tamperedFooterSignatureIsRejected fail (nothing thrown),
    which shows the tampered bytes actually reach the reader and the tag check is
    what rejects them.

    A true timing measurement is impractical to assert deterministically in a unit
    test, so this PR verifies functional equivalence (accept valid, reject tampered)
    rather than the timing property itself.

    Are there any user-facing changes?

    No. This is an internal hardening of the footer-signature check with identical
    observable behavior (same acceptance and rejection outcomes, same exception on
    mismatch). No API, format, or configuration changes.

    Diff: 361 lines (+270 / -91) across 4 files Reviewer: ggershinsky Review duration: 149316m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 361 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3655"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%