Add post-filter suppress_schema_paths and apply to S-313 common-library hints#176
Open
hdamker wants to merge 1 commit intocamaraproject:validation-frameworkfrom
Open
Add post-filter suppress_schema_paths and apply to S-313 common-library hints#176hdamker wants to merge 1 commit intocamaraproject:validation-frameworkfrom
hdamker wants to merge 1 commit intocamaraproject:validation-frameworkfrom
Conversation
Reusable per-rule JSON-path allowlist in the post-filter. Findings matching an entry (exact or prefix with dot boundary) are dropped before applicability/severity processing. The Spectral adapter extracts Spectral's JSONPath into finding.schema_path. S-313 uses it to silence ten known-unactionable hints on CAMARA_common.yaml and CAMARA_event_common.yaml. Upstream OWASP rule is untouched — Spectral still produces the full finding set.
Contributor
Author
|
@rartych could you shortly check validation/rules/spectral-rules.yaml ... if these are the rules to suppress findings from CAMARA_common.yaml and CAMARA_event_common.yaml? Or should we fix some of the findings in the definitions? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
enhancement
What this PR does / why we need it:
Adds a new reusable post-filter hook
suppress_schema_pathson rule metadata and wires it up for S-313. Any rule that accumulates known-unactionable hints can opt in by listing specific JSON paths; matching findings are dropped before applicability/severity processing. The Spectral ruleset is not modified —owasp:api4:2023-string-restrictedstays enabled atwarnseverity, Spectral continues to produce the full finding set, and the post-filter is the only thing that hides the known-unactionable entries. This keepsresolved: truebehaviour intact, so string fields in API-local modules undercode/modules/reachable only via$refcontinue to be checked.Changes:
validation/schemas/findings-schema.yaml— new optional fieldschema_path(dot-joined JSONPath of the offending node within the source document).validation/engines/spectral_adapter.py—normalize_findingextracts Spectral'sraw["path"](JSONPath array), dot-joins it, and stores it asfinding["schema_path"]. Spectral's internal source mapping already reports canonical paths within the source file (e.g.components.schemas.ErrorInfo.properties.codeon a finding attributed tocode/common/CAMARA_common.yaml), so no further normalisation is needed.validation/schemas/rule-metadata-schema.yaml— new optional fieldsuppress_schema_paths(list of strings).validation/postfilter/metadata_loader.py—RuleMetadatadataclass gainssuppress_schema_paths: Tuple[str, ...](defaults to empty). Parser reads the new field and defensively drops non-string entries.validation/postfilter/engine.py— new helper_is_suppressed_by_schema_path(finding, rule)with exact-or-prefix-with-dot-boundary semantics. Called fromrun_post_filterimmediately after metadata lookup; matching findings are dropped entirely so they never reach applicability evaluation, severity resolution, or the output.validation/rules/spectral-rules.yaml— S-313 getssuppress_schema_pathspopulated with the ten field paths currently firing onCAMARA_common.yamlandCAMARA_event_common.yaml. Rule ID, engine binding, default severity, and hint are unchanged.Why entries are specific fields, not whole components:
The allowlist names exact field paths so any new unconstrained string added to a common schema still surfaces as a hint. A codeowner or Commonalities maintainer can then decide whether the new field is also intentionally unconstrained (and should join the allowlist) or whether it should actually be constrained upstream in Commonalities.
Match semantics:
Exact equality (
components.schemas.ErrorInfo.properties.code) OR prefix with dot boundary. The boundary check prevents look-alike neighbours likecomponents.schemas.ErrorInfoExtended.properties.codefrom being false-matched by anErrorInfoentry.Which issue(s) this PR fixes:
Fixes #175
Special notes for reviewers:
test_spectral_adapter.py— 4 tests forschema_pathextraction (dot-joined string, mixed string/int segments, missing path → None, empty path → None)test_postfilter_metadata.py— 4 tests forsuppress_schema_pathsparsing (list → tuple, empty list, invalid type raises, non-string entries dropped)test_postfilter_engine.py— 9 unit tests for_is_suppressed_by_schema_path(exact match, prefix-with-boundary, look-alike does NOT match, missing/empty schema_path falls through, first-match-wins) + 3 integration tests viarun_post_filter(suppressed dropped, non-suppressed kept, mixed batch)validation/tests/pass locally.camaraproject/ReleaseTest@regression/r4.1-main-baseline: 14 S-313 raw findings → 10 common-library entries suppressed → 4 API-specific entries kept. The four kept correspond tocomponents.schemas.{CreateResource,Resource}.properties.nameinsample-service.yamlandsample-implicit-events.yaml.camaraproject/ReleaseTestneed a recapture before the next canary run will go green. Expected deltas:regression/r4.1-main-baselinehints 27 → 17,regression/r4.1-broken-spec-api-metadatahints 30 → 20 (errors and warnings unchanged at 2 and 4). Fixture branches on ReleaseTest are updated viavalidation/scripts/regression_runner.py --capture <branch>dispatched against the newvalidation-frameworkHEAD.Changelog input
Additional documentation
This section can be blank.