feat(remediation): validate upgrade suggestions against transitive dependency graph (#708)#790
feat(remediation): validate upgrade suggestions against transitive dependency graph (#708)#790dinesh9997 wants to merge 19 commits into
Conversation
… automatic hashing invalidation
…nt test pollution
utksh1
left a comment
There was a problem hiding this comment.
This needs changes before it can merge.
Blocking issues:
-
build_dependency_graph(target) falls back to this SecuScan repository’s backend/frontend manifests whenever the supplied target does not contain requirements/package files. For normal URL/IP scan targets, that means remediation safety is computed against SecuScan’s own dependencies, not the scanned project. That can mark unrelated remediation advice safe/unsafe based on the wrong dependency graph.
-
_build_result_contract wraps the whole remediation validation block in
except Exception: pass, so parser bugs, malformed manifests, and version parsing errors disappear silently. At minimum, log the failure with task/plugin context and avoid adding misleading safety metadata when validation did not actually run. -
The feature adds top-level API fields but only sources them from metadata during deserialization. Please add route/serialization coverage that proves list/detail finding responses expose these fields only when they came from validated remediation metadata.
-
The resolver includes deterministic mock transitive dependencies in production code. Test fixtures should live in tests, not in runtime remediation logic.
…lled on cache hit
… mock test dependencies, and add serialization tests
|
Hi @utksh1 ,
2.Relocated Test Mock Fixtures: Removed the hardcoded get_mock_dependencies registry from remediation.py. Test fixtures now live entirely in test_remediation_safety.py, where get_python_transitive_dependencies is mocked dynamically. 3.Atomic Safety Enrichment: Validation is now performed atomically inside executor.py (_build_result_contract). If an exception or parser crash occurs, we print warning logs containing task and plugin contexts, and avoid adding any partial or misleading safety metadata to the findings. 4.Integration Route Coverage: Created test_routes_remediation_safety.py to test both /findings (list) and /finding/{finding_id} (detail) responses, ensuring safe_to_apply, compatible_range, and alternatives are exposed correctly only when sourced from validated remediation metadata. 5.Formatting Hygiene: Cleaned up all trailing whitespaces in the test files to pass the formatting checks. so let me know any changes needed to be done. |
utksh1
left a comment
There was a problem hiding this comment.
Thanks for the update. This still needs changes before merge.
The PR remains broader than the remediation graph fix and now includes .audit-config.yaml plus scan-cache/main/routes churn. The remediation change is security-sensitive and should be reviewable on its own.
Please remove the unrelated audit/config/cache/API churn and keep this focused on validating upgrade suggestions against the dependency graph with direct unit/integration coverage. Once the patch is narrow, the remaining remediation behavior can be reviewed properly.
73796d2 to
8aa1e83
Compare
|
Hi @utksh1, I have cleaned up this branch as requested: Reverted all unrelated .audit-config.yaml, cache.py, main.py, plugin metadata, and config/manifest changes back to the upstream base. |
utksh1
left a comment
There was a problem hiding this comment.
Rechecking after the latest merge from main: this is still blocked.
The frontend-checks job is failing on the current head. This remediation graph change also needs to stay focused on remediation dependency validation, without unrelated audit/config/cache/API churn, before it can be reviewed safely.
Resolves #708
Problem Statement
Remediation suggestions (such as version upgrades) generated by scanners could conflict with other existing project dependencies, resulting in dependency conflicts and broken builds when applied.
Solution Overview
Integrated a transitive dependency graph resolver that parses project manifests and validates recommended library upgrades against package version constraints.
requirements.txt/requirements-dev.txtand Node.jspackage.json/package-lock.json).^, tildes~, wildcards, partial versions) to PEP-440 specifiers usingpackaging.specifiersto enable standard Python version compliance checking."safe_to_apply"indicator,"compatible_range", and actionable"alternatives"(e.g., upgrading the parent package) inside finding metadata and exposes them as top-level fields in API payloads.Key Changes
backend/secuscan/remediation.py[NEW]: Encapsulates all package normalization, version cleaning, semver-to-pep440 conversion, lockfile/manifest parsing, and validation logic.backend/secuscan/models.py: Added optionalsafe_to_apply,compatible_range, andalternativesfields to the PydanticFindingschema.backend/secuscan/executor.py: Integrated validation logic into the executor's_build_result_contractnormalization phase.backend/secuscan/routes.py: Enriched findings deserialization helper and/finding/{finding_id}routes to expose safety indicators at the top level of responses.testing/backend/unit/test_remediation_safety.py[NEW]: Added 10 unit tests covering range translations, manifest parsing, safe/unsafe validations, and serialization.Verification and Testing Done
Automated Tests