Skip to content

fix(453): escape :.3f/:1f cells after formatting - #456

Merged
sromoam merged 1 commit into
awslabs:devfrom
mangeshraut712:fix/453-escape-format-cells
Oct 30, 2026
Merged

sromoam merged 1 commit into
awslabs:devfrom
mangeshraut712:fix/453-escape-format-cells

Conversation

@mangeshraut712

Copy link
Copy Markdown
Contributor

Summary

Fixes #453.

Numeric cells that use :.3f / :.1f were interpolated without escaping, so a caller-supplied numeric subclass whose __format__ returns markup could land in the page. Escape the formatted string at each of the five sites named in the issue:

  • field-performance table: Precision, Recall, F1
  • field-performance chart: bar value
  • confusion-matrix heatmap: percentage

generate_performance_gauge is intentionally left alone: int(score * 100) forces a plain int, so subclass __format__/__str__/__mul__ cannot reach the template (noted in the module docstring).

Test plan

  • Added regression tests that fail when any of the five escapes is removed (HF(float) for table/chart; hostile __truediv__+__mul__+__format__ for heatmap percentage)
  • Ordinary float values still render as 0.912 / 0.750 / 100.0%

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

A numeric subclass whose __format__ returns markup could land in the
field-performance table/chart and the confusion-matrix percentage cells.
Escape the formatted string at each of the five sites. Gauge stays
unescaped: int(score * 100) forces a plain int.

@digalaviz digalaviz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 063037f. Approving: all five sites named in #453 are escaped after formatting, and
removing any one escape fails a test. For ordinary values (float, int, numpy types, Decimal,
bool, NaN, infinities, zero, negatives) the table, chart, heatmap and full report render exactly as
on dev. The module docstring explains why the gauge is excluded, as #453 asks.

Merge order with #464: this PR conflicts with #464 in visualization_engine.py and
test_visualization_engine.py. In the source file, #464 escapes the confusion-matrix value and this
PR escapes the percentage on the adjacent line: keep both escaped lines. In the test file, each side
adds a class at the end: keep both classes. Taking either side whole drops the other side's escape
together with the test that guards it. Either order works; the second to land needs that resolution.

Non-blocking:

  • The table test gives the hostile value to all three cells, so its positive assertion holds when any
    one cell is escaped. A value in one cell at a time would pin each cell.
  • The payload contains no & or ", so escaping only < would also pass.
  • The docstring is not an f-string, so {{value:.Nf}} renders with doubled braces.
  • Both changed files lose their final newline.

@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-10-30T14:38:18+00:00
  • Time since scan: 2 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-10-30T14:35:32+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 4 0 0 6313 0 4 FAILED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 1 0 0 0 0 1 SKIPPED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Top 3 Hotspots

Files with the highest number of security findings:

Finding Count File Location
2 tests/comparators/test_anls_leaf_semantics.py
2 tests/structured_object_evaluator/test_rollup_node_semantics.py
1 tests/test_readme_examples.py

Detailed Findings

Show 5 actionable findings

Finding 1: SECRET-HEX-HIGH-ENTROPY-STRING

  • Severity: HIGH
  • Scanner: detect-secrets
  • Rule ID: SECRET-HEX-HIGH-ENTROPY-STRING
  • Location: tests/comparators/test_anls_leaf_semantics.py:89

Description:
Secret of type 'Hex High Entropy String' detected in file 'tests/comparators/test_anls_leaf_semantics.py' at line 89

Code Snippet:

Secret of type Hex High Entropy String detected

Finding 2: B108

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B108
  • Location: tests/comparators/test_anls_leaf_semantics.py:210-212

Description:
Probable insecure usage of temp file/directory.

Code Snippet:

uuid.UUID(int=1),
            pathlib.Path("/tmp/x"),
            b"bytes",

Finding 3: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1363-1369

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

def published_label(node: dict, section: str, object_lists: set) -> str:
            counts_objects = eval(  # noqa: S307
                cond.group(1),
                {},
                {"data": node, "section": section, "OBJECT_LISTS": object_lists},
            )
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 4: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1368-1370

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

)
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 5: B102

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B102
  • Location: tests/test_readme_examples.py:55-57

Description:
Use of exec detected.

Code Snippet:

with contextlib.redirect_stdout(out):
        exec(code, namespace)
    prints = [line for line in code.splitlines() if line.startswith("print(")]

Report generated by Automated Security Helper (ASH) at 2026-10-30T14:38:19+00:00

@sromoam
sromoam merged commit 434631c into awslabs:dev Oct 30, 2026
10 checks passed
sromoam pushed a commit that referenced this pull request Oct 30, 2026
The Documents card interpolated document_count into the page unescaped.
ProcessEvaluation validates the field as an int at construction, but not on
assignment or through model_construct, so a caller that assigns it, or builds
the model with model_construct, could put markup into the report. Document
data does not reach it: the bulk evaluator sets an int, and a results dict
falls back to 1.

The value now goes through html.escape like the other cells, and a test
assigns markup after construction and asserts it is escaped. It has the same
in-process-caller reachability as #453; #456 escapes the visualization_engine.py
cells, not this one.
@digalaviz

Copy link
Copy Markdown
Contributor

Thank you for this fix, which closed #453.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: ':.3f' and ':.1f' placeholders in visualization_engine are unescaped, so a caller-supplied numeric subclass reaches the page as markup

3 participants