fix(desktop): validate scope and all provenance digests before showing details
davoodmehraban89 committed
Oct 31, 2026 at 21:53 UTC
0eaf18094d51404994e82a13a22c8b08975aa004
1 file changed
+24
backend/src/aram_backend/desktop_five_statement_integrity.py
+24
@@ -65,8 +65,22 @@ def validate_desktop_pipeline_result(result: FiveStatementPipelineResult) -> Non
65
or not re.fullmatch(r"[0-9a-f]{64}", candidate.source_sha256)):
66
raise CoverageError("DESKTOP_PREVIEW_SOURCE_HASH_INVALID")
67
source_hashes.add(candidate.source_sha256)
68
+ if (not isinstance(candidate.company_code, str)
69
+ or not candidate.company_code
70
+ or candidate.company_code != candidate.company_code.strip()
71
+ or type(candidate.fiscal_year) is not int
72
+ or candidate.fiscal_year <= 0):
73
+ raise CoverageError("DESKTOP_PREVIEW_SCOPE_INVALID")
74
companies.add(candidate.company_code)
75
years.add(candidate.fiscal_year)
76
+ for hash_field in (
77
+ "note_references_sha256", "presentation_policies_sha256",
78
+ "transaction_ledger_sha256", "classification_policies_sha256",
79
+ ):
80
+ if hasattr(candidate, hash_field):
81
+ digest = getattr(candidate, hash_field)
82
+ if not isinstance(digest, str) or not re.fullmatch(r"[0-9a-f]{64}", digest):
83
+ raise CoverageError("DESKTOP_PREVIEW_PROVENANCE_HASH_INVALID")
84
eligible_field = (
85
"balanced_for_analyst_review" if isinstance(candidate, TrialBalanceDiagnostic)
86
else "eligible_for_analyst_review"
@@ -100,8 +114,18 @@ def validate_desktop_pipeline_result(result: FiveStatementPipelineResult) -> Non
114
reconciliation = result.reconciliation
115
if (len(source_hashes) != 1
116
or reconciliation.source_sha256 not in source_hashes
117
+ or not isinstance(reconciliation.source_sha256, str)
118
+ or not re.fullmatch(r"[0-9a-f]{64}", reconciliation.source_sha256)
119
or reconciliation.same_source_snapshot is not True):
120
raise CoverageError("DESKTOP_PREVIEW_SOURCE_SNAPSHOT_MISMATCH")
121
+ if (not isinstance(reconciliation.cash_flow_transaction_ledger_sha256, str)
122
+ or not re.fullmatch(r"[0-9a-f]{64}", reconciliation.cash_flow_transaction_ledger_sha256)
123
+ or not isinstance(reconciliation.cash_note_selection_sha256, str)
124
+ or not re.fullmatch(r"[0-9a-f]{64}", reconciliation.cash_note_selection_sha256)):
125
+ raise CoverageError("DESKTOP_PREVIEW_RECONCILIATION_HASH_INVALID")
126
+ if (not isinstance(reconciliation.findings, tuple)
127
+ or any(not isinstance(item, str) or not item for item in reconciliation.findings)):
128
+ raise CoverageError("DESKTOP_PREVIEW_RECONCILIATION_FINDINGS_INVALID")
129
if companies != {reconciliation.company_code} or years != {reconciliation.fiscal_year}:
130
raise CoverageError("DESKTOP_PREVIEW_SCOPE_MISMATCH")
131
if (result.balance_sheet.note_references_sha256