Skip to content

fix: decrypt CRM regulatory_fields + related_parties PII#320

Merged
arthurkz merged 1 commit into
mainfrom
hotfix/crm-regulatory-fields-decryption
Jul 17, 2026
Merged

fix: decrypt CRM regulatory_fields + related_parties PII#320
arthurkz merged 1 commit into
mainfrom
hotfix/crm-regulatory-fields-decryption

Conversation

@arthurkz

Copy link
Copy Markdown
Contributor

Description

Fixes CCS-0011: the CRM extraction path was passing regulatory_fields.participant_document and related_parties[].document through as raw AES-GCM ciphertext instead of decrypting them. This adds decryptRegulatoryFields (map-shaped) and decryptRelatedParties (slice-shaped) to the existing decryptNestedFields path, reusing the same *libCrypto.Crypto instance already used for banking_details.account.

Fail-closed by design: an undecryptable value returns a wrapped error (naming the field/index, never echoing the raw value) rather than silently passing ciphertext through.

Type of Change

  • fix: Bug fix

Breaking Changes

None.

Testing

  • make test passes (36 decrypt tests pass — real crypto round-trip, not mocks)

Covers: happy-path decryption via the production entrypoint, all no-op/shape-drift branches (absent, nil, wrong-type, non-map elements), and fail-closed errors (invalid base64, tampered ciphertext, correct index reporting, fail-fast).

Architectural Checklist

  • No panic() in production paths
  • Errors wrapped with %w
  • Handlers stay thin (parse, validate, call service)

Related Issues

Closes #

@arthurkz
arthurkz requested a review from a team as a code owner July 17, 2026 11:10
@lerian-studio

Copy link
Copy Markdown
Contributor

Lerian Library Version Check

Library Current Latest Status
lib-auth/v2 v2.9.0 v2.9.0 Current
lib-commons/v5 v5.10.0 v5.10.0 Current
lib-observability v1.1.0 v1.1.0 Current
lib-streaming v1.8.0 v1.9.0 Outdated
fetcher/pkg/engine v1.0.13 skipped Skipped (ignore file)

1 outdated | 3 current | 1 skipped | 0 unknown

Bump the outdated libraries, or add temporary entries to .lerianstudiolibignore.

@lerian-studio lerian-studio added size/L PR changes 500-999 lines component: worker Worker component area: tests Unit, integration and end-to-end tests labels Jul 17, 2026
@lerian-studio

lerian-studio commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Validation Summary

✅ PR Mergeable — no blocking failures

Check Status Blocking
Source Branch ✅ success yes
PR Title ✅ success yes
PR Description ✅ success yes
PR Size ✅ success no
Auto Labels ✅ success no
PR Metadata ✅ success no

🔍 View workflow run

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Walkthrough

CRM nested decryption now handles regulatory_fields.participant_document and related_parties[].document, with no-op handling for unsupported shapes and tests for invalid, tampered, and partially populated data.

Changes

CRM nested decryption

Layer / File(s) Summary
Regulatory field decryption
components/worker/internal/services/extract_crm_data.go, components/worker/internal/services/extract_crm_data_test.go
Adds conditional decryption for regulatory_fields.participant_document and tests successful, no-op, invalid-ciphertext, and tampered-ciphertext cases.
Related-party document decryption
components/worker/internal/services/extract_crm_data.go, components/worker/internal/services/extract_crm_data_test.go
Decrypts document fields in map-shaped related_parties elements while skipping unsupported elements and testing fail-fast errors.
Nested decryption wiring and CRM coverage
components/worker/internal/services/extract_crm_data.go, components/worker/internal/services/extract_crm_data_test.go
Invokes both helpers from decryptNestedFields and extends plugin CRM fixtures and assertions for the regulatory document field.

Sequence Diagram(s)

sequenceDiagram
  participant decryptNestedFields
  participant decryptRegulatoryFields
  participant decryptRelatedParties
  participant decryptFieldValue
  decryptNestedFields->>decryptRegulatoryFields: decrypt regulatory_fields.participant_document
  decryptRegulatoryFields->>decryptFieldValue: decrypt participant_document
  decryptNestedFields->>decryptRelatedParties: decrypt related_parties[].document
  decryptRelatedParties->>decryptFieldValue: decrypt each document
Loading
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hotfix/crm-regulatory-fields-decryption

Comment @coderabbitai help to get the list of available commands.

@lerian-studio

Copy link
Copy Markdown
Contributor

📊 Unit Test Coverage Report: fetcher-worker

Metric Value
Overall Coverage 87.4% ✅ PASS
Threshold 80%

Coverage by Package

Package Coverage
github.com/LerianStudio/fetcher/v2/components/worker/internal/services 90.0%

Generated by Go PR Analysis workflow

@lerian-studio

Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — manager

🚫 PR Blocked — 1 blocking finding

Stage Status Blocking?
Filesystem Scan ✅ Clean
Docker Image Scan ⚠️ 1 finding 🔴 Yes
Docker Hub Health Score ✅ Clean
Pre-release Version Check ✅ Clean

Trivy

Filesystem Scan

✅ No vulnerabilities or secrets found.

Docker Image Scan

Severity Vulnerability Title
LOW CVE-2026-56852 Infinite loop on invalid input in golang.org/x/text

Docker Hub Health Score Compliance

✅ Policies — 4/4 met

Policy Status
Default non-root user ✅ Passed
No fixable critical/high CVEs ✅ Passed
No high-profile vulnerabilities ✅ Passed
No AGPL v3 licenses ✅ Passed

Pre-release Version Check

✅ No unstable version pins found.


🔍 View full scan logs

@lerian-studio

Copy link
Copy Markdown
Contributor

📊 Unit Test Coverage Report: fetcher-manager

Metric Value
Overall Coverage 89.7% ✅ PASS
Threshold 80%

Coverage by Package

Package Coverage
github.com/LerianStudio/fetcher/v2/components/manager/cmd/huma-spec 33.4%
github.com/LerianStudio/fetcher/v2/components/manager/internal/adapters/cache 100.0%
github.com/LerianStudio/fetcher/v2/components/manager/internal/adapters/http/in 89.4%
github.com/LerianStudio/fetcher/v2/components/manager/internal/services/command 92.8%
github.com/LerianStudio/fetcher/v2/components/manager/internal/services/query 96.4%

Generated by Go PR Analysis workflow

@arthurkz arthurkz changed the title fix(worker): decrypt CRM regulatory_fields + related_parties PII fix: decrypt CRM regulatory_fields + related_parties PII Jul 17, 2026
@lerian-studio

Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — worker

🚫 PR Blocked — 1 blocking finding

Stage Status Blocking?
Filesystem Scan ✅ Clean
Docker Image Scan ⚠️ 1 finding 🔴 Yes
Docker Hub Health Score ✅ Clean
Pre-release Version Check ✅ Clean

Trivy

Filesystem Scan

✅ No vulnerabilities or secrets found.

Docker Image Scan

Severity Vulnerability Title
LOW CVE-2026-56852 Infinite loop on invalid input in golang.org/x/text

Docker Hub Health Score Compliance

✅ Policies — 4/4 met

Policy Status
Default non-root user ✅ Passed
No fixable critical/high CVEs ✅ Passed
No high-profile vulnerabilities ✅ Passed
No AGPL v3 licenses ✅ Passed

Pre-release Version Check

✅ No unstable version pins found.


🔍 View full scan logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/worker/internal/services/extract_crm_data.go`:
- Around line 635-643: Rename the loop-local type-assertion boolean from ok to
isParty in the relatedParties loop in
components/worker/internal/services/extract_crm_data.go:635-643, updating its
conditional use. Apply the same rename in the assertion loop in
components/worker/internal/services/extract_crm_data_test.go:2555-2561.
- Around line 607-610: Malformed sensitive document values bypass fail-closed
validation. In extract_crm_data.go at lines 607-610, validate regulatory
participant_document values as non-empty strings before decrypting; at lines
646-649, apply the same validation to related-party documents and include the
document index in errors. Add empty and non-string regulatory cases in
extract_crm_data_test.go lines 2398-2429 and corresponding related-party cases
in lines 2669-2695.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 200a55cf-f4e4-4e6d-a090-964742a4ba5a

📥 Commits

Reviewing files that changed from the base of the PR and between 09309d7 and 1aa00fb.

📒 Files selected for processing (2)
  • components/worker/internal/services/extract_crm_data.go
  • components/worker/internal/services/extract_crm_data_test.go

Comment thread components/worker/internal/services/extract_crm_data.go
Comment thread components/worker/internal/services/extract_crm_data.go
@arthurkz
arthurkz merged commit 72d015a into main Jul 17, 2026
39 of 44 checks passed
@fredcamaral
fredcamaral deleted the hotfix/crm-regulatory-fields-decryption branch July 21, 2026 18:00
fredcamaral added a commit that referenced this pull request Jul 24, 2026
Back-merge the 3.0.x hotfix line (CRM regulatory_fields decryption, #320) and
release chores (3.0.1, 3.0.2) into the 3.1.0-beta line so release-candidate
promotes to main without conflicts. Resolutions: go.mod/go.sum kept from
release-candidate (newer, CI-green dependency pair); pkg/engine/CHANGELOG.md
unioned to preserve both stable (1.1.1/1.1.0) and beta (1.1.0-beta.x) entries.

Claude-Session: https://claude.ai/code/session_01WscfYUmQmJ7KWNGE18mXNB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Unit, integration and end-to-end tests component: worker Worker component size/L PR changes 500-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants