security: switch advisory-lock key derivation from MD5 to SHA256 (3 sites) + ERB rationale — #239

Merged
JA
2mo ago
+4-3

Summary

Implements the code-fix option QA recommended for the 4 Codacy findings carried by issue #239 (originally observed on PR #232): switch advisory-lock key derivation from MD5 to SHA256 across the three MD5 sites, and add a one-line inline rationale on the ERB-render test line.

The digest feeds only pg_try_advisory_lock / pg_advisory_unlock — a 62-bit lock-key derivation, not a secret or auth boundary. SHA256 matches the stronger HMAC-SHA256 idiom already used in app/models/sso_identity_block.rb and removes the Codacy MD5 rule across all three sites. The 62-bit modulo (to_i(16) % (2**62)) is preserved unchanged — no behavioral or concurrency change.

Changes (4 files)

  • app/models/financekit/downstream.rb — Digest::MD5 → Digest::SHA256
  • app/jobs/demo_family_refresh_job.rb — Digest::MD5 → Digest::SHA256
  • app/jobs/generate_insights_job.rb — Digest::MD5 → Digest::SHA256
  • test/lib/generators/provider/family_generator_test.rb — one-line comment documenting the ERB false positive

Full diff is confined to these four locations (3 digest swaps + 1 comment). Nothing else changed.

QA approval

QA approved the #239 assessment (all 4 findings non-exploitable) and recommended the code fix over Codacy suppressions — comment id 5850877747 on issue #239:

Recommendation for the owner: the SHA256 option is the cleaner choice, and doing it across the three MD5 lock-keying sites (downstream.rb, demo_family_refresh_job.rb, generate_insights_job.rb) in one pass matches the sso_identity_block.rb HMAC-SHA256 idiom — better than per-site Codacy suppressions. The ERB test finding is a pure false positive and is best handled with a Codacy suppression on that file path (or a one-line inline rationale comment).

Verdict: Approved (assessment accurate; owner may act).
Full context: jaysbeekay/sure#239 (comment https://github.com/jaysbeekay/sure/issues/239#issuecomment-5850877747).

Tests

The pr.yml workflow runs the shared ci.yml suite on PR open/sync. Relevant coverage: Financekit::Downstream lock behavior, the two jobs, and family_generator_test.rb. (Result linked below via the CI check run; not re-verified locally — the worker environment has no Ruby toolchain or network write path to run rails test, so the authoritative signal is the PR's own CI.)

Remaining owner action (explicitly not this PR)

  • Codacy-dashboard baseline/suppress for the “manual ERB template” rule on test/lib/generators/provider/family_generator_test.rb — Codacy is login-gated, so this is an owner action, not a code change. The inline comment above is the code-side piece.
  • Out of scope per #239: the #234/#235 threads (FinanceKit body bound / Jev redaction, cross-family account visibility), the EXTERNAL_ASSISTANT_TOKEN line in app/controllers/settings/hostings_controller.rb (separate accepted false positive, upstream we-promise/sure#3674), and PR #238's 2 findings (tracked by t_2123e5b3).

Fixes #239.

Summary by CodeRabbit

  • Chores
    • Updated internal coordination safeguards used by background processing jobs. Their locking behavior remains unchanged.
    • Clarified a test note about trusted template inputs. No user-facing behavior changes.