Skip to content

fix(454): coerce document_files keys and paths in the gallery - #455

Merged
digalaviz merged 5 commits into
awslabs:devfrom
mangeshraut712:fix/454-gallery-str-coerce
Nov 8, 2026
Merged

digalaviz merged 5 commits into
awslabs:devfrom
mangeshraut712:fix/454-gallery-str-coerce

Conversation

@mangeshraut712

Copy link
Copy Markdown
Contributor

Why

generate_document_gallery passes document_files keys and paths straight to html.escape. When either side is a non-str (typical once doc_id comes off an integer DataFrame column), html.escape raises AttributeError: 'int' object has no attribute 'replace'. generate_report catches that and returns success=False with no page written — silent if the caller ignores .success.

Measured on current dev the same way #454 describes for 1.0.1: {1001: "scan.png"} and {"doc-1": 1001} both blow up in image and PDF modes.

What changed

In SectionGenerator.generate_document_gallery, coerce both the key and the path with str() before every html.escape call (image branch and PDF branch). Same shape as the doc_id coercion _load_individual_results gained for 1.0.1.

Deliberate collision: after conversion, integer 1001 and string "1001" are the same gallery key. That matches the filter-side behaviour 1.0.1 already records for JSONL doc_id, so pairing a document with its page stays consistent across those two surfaces.

No CHANGELOG edit: the 1.0.1 sentence that the gallery still requires str keys and paths stays until that release notes cycle; this PR is the 2.0.0 fix #454 targets.

Scope / blast radius

Verification

uv run pytest tests/reporting/html/test_section_generator.py -k gallery -v
# 7 passed (3 existing + 4 new: image/pdf × int key/int path)
uv run ruff check src/stickler/reporting/html/section_generator.py tests/reporting/html/test_section_generator.py
# All checks passed

Removing either str() makes the matching new test fail with the AttributeError above.

Fixes #454

html.escape requires str. Integer keys or paths (common when doc_id
comes off a DataFrame column) raised AttributeError and generate_report
returned success=False with no page. Coerce both sides before escape so
int 1001 and "1001" also agree as the gallery key.

@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 651087a. Thank you for this. The four str() calls are in the right places, and
removing any one of them fails its own test. Two gaps remain before this closes #454.

Requested changes:

  • The tests use only a Python int, so they pass for code that coerces only int. With that
    narrower rule, an np.int64 key (what indexing an integer DataFrame column gives) still makes
    generate_report return success=False in both modes, and a pathlib.Path path still makes
    generate_document_gallery raise. Please add a test with an np.int64 key and a Path path, in
    image and PDF mode.
  • The collision decision is stated but not asserted. #454 asks for it not to be left implied.
    With {1001: "a.png", "1001": "b.png"} the gallery renders two items with the same label, and in
    PDF mode two items with data-doc-id="1001"; the report's script then keeps only one of them.
    Please either reject a collision after conversion, or keep the current behaviour and add a test
    that asserts it. The code comment "str() makes int 1001 and '1001' agree as the gallery key"
    should match whichever you choose.

Also worth changing:

  • All four tests call generate_document_gallery directly. One test through generate_report with
    {1001: path} that asserts result.success would cover the symptom #454 reports.
  • The PR body says the CHANGELOG sentence "stays", but that sentence is not on dev, so there is
    nothing to keep. An entry under [Unreleased] ### Fixed for this change would be enough.

Dependency on #464: on dev alone, a numeric doc_id still fails generate_report in the
non-matches table, which #464 fixes. With #464 merged, this PR works end to end, and the gallery
ids agree with the embedded doc_ids. It merges cleanly with #464 and with #466.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

@digalaviz Addressed in f2df861: added an np.int64 key + Path value test in image and PDF mode, kept the current collision behaviour and asserted it (both entries preserved, in order, in both modes) with the code comment updated to match, added a generate_report test with {1001: path} asserting success, and moved the CHANGELOG entry under [Unreleased] Fixed. Branch is merged with current dev.

mangeshraut712 and others added 2 commits November 3, 2026 15:23
…odes

Assert generate_report succeeds in image and pdf modes when document_files
uses an np.int64 key and a Path value, addressing reviewer feedback on awslabs#454.
@digalaviz digalaviz self-assigned this Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-08T21:11:44+00:00
  • Time since scan: 2 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-08T21:09:03+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 6 0 0 6657 0 6 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 4 Hotspots

Files with the highest number of security findings:

Finding Count File Location
2 tests/comparators/test_anls_leaf_semantics.py
2 .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py
2 tests/structured_object_evaluator/test_rollup_node_semantics.py
1 tests/test_readme_examples.py

Detailed Findings

Show 7 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: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Finding 3: 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 4: 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 5: 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 6: 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(")]

Finding 7: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Report generated by Automated Security Helper (ASH) at 2026-11-08T21:11:45+00:00

@digalaviz

Copy link
Copy Markdown
Contributor

Reviewed at a6486f4. Both items from my last review are covered: f2df861 asserts the colliding-id case ({1001: ..., "1001": ...} keeps two items, in order, in image and PDF mode), and a6486f4 adds the np.int64 key and Path path through generate_report in both modes. CI passes on this head, and it merges cleanly with current dev.

One non-blocking suggestion: the a6486f4 test only checks '1001' in html, which an unrelated 1001 on the page would also satisfy. Asserting alt="1001" (image) and data-doc-id="1001" (PDF) would pin the gallery entry itself.

@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.

Approving at a6486f4, per the comment above.

@digalaviz
digalaviz merged commit ce6c100 into awslabs:dev Nov 8, 2026
10 checks passed
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]: generate_document_gallery fails silently on a non-str document_files key or path

3 participants