Skip to content

fix(report): use literal document IDs for PDF controls - #555

Merged
digalaviz merged 5 commits into
awslabs:devfrom
mangeshraut712:fix/476-pdf-element-ids
Nov 18, 2026
Merged

digalaviz merged 5 commits into
awslabs:devfrom
mangeshraut712:fix/476-pdf-element-ids

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Part of #476, item 2 only (PDF viewer canvas lookup). The umbrella issue stays open.

Description of changes:

loadPDF in reporting/html/interactive/main.js looked up the canvas, loading and error elements with CSS selectors built from the raw doc_id (getElement(#${canvasId})). For invoice_1.pdf the selector reads as id pdf-canvas-invoice_1 plus class pdf and returns null; for ids like inv 001 or a:b it throws a SyntaxError inside setTimeout. Either way the gallery stays on "Loading PDF...".

The seven dynamic lookups (initial canvas/loading/error, render completion, page label, previous and next controls) now use document.getElementById with the literal id, so no doc_id is ever parsed as a selector. No other behaviour changes.

Tests: tests/reporting/html/test_pdf_document_ids.py drives the real main.js in a Node VM with a minimal DOM (pdf_document_ids.cjs) across plain, dotted, spaced, : and # ids, covering load, page navigation and the failure display. Adds the directory README that AGENTS.md asks for.

  • On dev ce6c100: 12 failed, 4 passed (the 4 are ids that happen to be valid CSS identifiers).
  • With this change: 16 passed.
  • Full suite: 4117 passed, 13 skipped, 1 xfailed (Python 3.12.15, stickler imported from this checkout's src).
  • Changed-file Ruff and formatting pass; node --check passes; repository-wide Ruff has the same 17 findings as unmodified dev.

A real-browser check (Safari, PDF.js stubbed offline) gave 4/16 on dev and 16/16 with the patch. Real PDF decoding was not re-tested.

AI-assisted implementation, testing and review.

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

Current-base validation (2026-11-13): reconciled dev 7034ec07ddf6084a0541e1c48c3fe8418c737922 without rewriting history. Python 3.12.16 full non-integration suite with optional LLM/BERT dependencies: 3,525 passed, 2 skipped, 1 xfailed; repository-wide Ruff and diff checks pass. Tests explicitly import this checkout. Independent merge review found no blocking issues. Hosted workflows still require maintainer authorization. PDF behavior tests use a simulated DOM/PDF.js; this does not claim live-browser visual validation.

Address the PDF viewer item in awslabs#476. Keep canvases, load/error messages, page labels and navigation controls reachable for document IDs containing spaces or CSS punctuation.

AI-assisted implementation with independent code review. Offline regression cases reproduce 12 failures on dev and all 16 pass here. Full suite: 4117 passed, 13 skipped, 1 xfailed. Safari DOM check passes all 16 cases with PDF.js stubbed; real PDF decoding is not newly tested.

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

needs changes

The fix is correct. One thing is missing: a CHANGELOG.md entry.

Missing CHANGELOG entry. git diff origin/dev...a91ab9e -- CHANGELOG.md is empty. This fixes a bug a user could hit (the PDF gallery stays on "Loading PDF..." for IDs such as invoice_1.pdf). RELEASING.md requires an entry for that:

stickler/RELEASING.md

Lines 99 to 103 in a91ab9e

### What belongs in the changelog
Entries are for changes a user can observe. A PR needs one when it changes
behaviour, an exported format, a public signature, a default, or a dependency,
and when it fixes a bug someone could have hit.

Add one bullet under [Unreleased] > ### Fixed with Refs #476, not a closing keyword, because #476 stays open.

Verified and cleared

  • PR body numbers reproduce. The new harness gives 12 failed / 4 passed on dev main.js and 16 passed at head. The full suite gives 4117 passed, 13 skipped, 1 xfailed.
  • Real browser (headless Chrome, merged with current dev): I tested 12 document IDs, including invoice_1.pdf, inv 001, a:b, a"b, </script><script>…, <img onerror>, attribute-breakout and JS-breakout strings, and a U+2028 ID. 12 of 12 viewers loaded and paged. No injected code ran, and the page threw no errors. On dev, 2 of 12 loaded. The ID only reaches getElementById, .id and textContent, so this does not reopen the 1.0.1 (#475) injection fixes.
  • Mutations: reverting each of the seven lookups is caught (6–12 of 16 cases fail). Setting isEvalSupported: true fails 16 of 16, so the CVE-2024-4367 mitigation is pinned.
  • No conflict with dev. CI has not run on the head commit yet.

Non-blocking (low)

  • The Node harness's fake getElementById finds elements that were never attached, so deleting appendChild(navControls) still passes.
  • test_pdf_document_ids.py:16 reads main.js from the repo path, not the file the reporter embeds.

Add an [Unreleased] > Fixed entry for the PDF viewer lookups, as RELEASING.md asks for a user-visible bug fix. Refs awslabs#476 rather than closing it, since the umbrella issue stays open.
@mangeshraut712

Copy link
Copy Markdown
Contributor Author

@vawsgit Added the CHANGELOG entry in fe7010f. It is one bullet under [Unreleased] > ### Fixed with Refs #476 and no closing keyword. test_pdf_document_ids.py still gives 16 passed. Could you re-review?

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

Thanks for this, and for adding the CHANGELOG entry so quickly. The fix reads well, and nothing else in main.js builds a selector from a document ID.

Must fix

  • CHANGELOG.md now conflicts with dev: the #478 entry landed in the same spot at the top of ### Fixed. Merging dev and keeping both bullets should be all it takes.

Smaller

  • Optional: the headline "loads documents whose IDs are not CSS identifiers" (CHANGELOG.md:24) is a touch broader than the fix. An ID with a carriage return or NUL still shows no PDF, on this branch and on dev, because captureDocumentFileData (main.js:149-161) keys files by the parsed <strong> text, which the HTML parser normalizes. Not a regression and not something this PR needs to fix. Narrowing the wording (for example "IDs that contain spaces or CSS punctuation") or leaving it for us to track separately are both fine.

Measured against this branch in headless Chrome: with 15 document IDs, including quotes, spaces, :, #, [, </script>, an onerror image tag, attribute and JS string breakouts, U+2028 and CJK, every PDF viewer loaded and paged, and no injected code ran. With dev's main.js, only 3 of the 15 loaded. Once the conflict is resolved and CI is green, this looks good to merge from my side.

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

needs changes

There is one blocker. CHANGELOG.md conflicts with current dev, so GitHub cannot merge this PR. CI has never run on it either: gh pr checks 555 reports "no checks reported", because the pull_request workflows do not start while the merge ref cannot be built. The code fix is correct. Once the conflict is resolved and CI is green, this PR is good to merge.

Required change

  1. Merge current dev into fix/476-pdf-element-ids. Keep both the #478 bullet from dev and this PR's PDF-viewer bullet under [Unreleased] > ### Fixed. See the inline comment on CHANGELOG.md.

Previous review (on a91ab9e)

  • Missing CHANGELOG entry: fixed in fe7010f (CHANGELOG.md#L24-L29). The entry is under Unreleased and uses Refs #476 with no closing keyword. That matches the PR covering only item 2 of #476. But dev has since added a bullet at the same place, which caused the conflict above.
  • Low, non-blocking, still open: the Node harness's fake getElementById also finds elements that were never attached. Deleting pdfContainer.appendChild(navControls); still gives 0/16 failures.
  • Low, non-blocking, still open: tests/reporting/html/test_pdf_document_ids.py:16 reads main.js from the repo path, not from the copy the reporter embeds.

What I verified (head 5745260, stickler imported from the PR worktree's src)

  • True diff: git diff origin/dev... touches 6 files. They are CHANGELOG.md, main.js (+8/-7), the new Node harness, the new pytest wrapper and two READMEs. The two "reconcile" merges bring in nothing else.
  • Node harness: dev's main.js fails 12/16 cases. Head fails 0/16. tests/reporting/html gives 184 passed.
  • Mutation tests:
    • Reverting the canvas, loading or error lookup fails 12/16 each.
    • Reverting the render-loading, page-info, prev or next lookup fails 6/16 each.
    • isEvalSupported: true fails 16/16, so the CVE-2024-4367 mitigation is pinned.
    • Dropping the display='block' on the canvas or the error element fails 8/16 each.
  • Real browser: I generated reports with EvaluationHTMLReporter.generate_report(...) from real 2-page PDFs. I drove them in headless Chrome with PDF.js 3.11.174 and tried 12 document IDs.
    • The IDs were: invoice_1.pdf, inv 001, a:b, a[b], a"b, a#b, 請求書, 1abc, a\b, a </script> payload, a ');...(' payload and plain invoice_1.
    • Head: 12/12 loaded and paged to "Page 2 of 2". No injected code ran.
    • dev: 3/12 loaded. The others threw SyntaxError: ... is not a valid selector or matched nothing.
  • Full suite (--extra llm --extra bert): 4197 passed, 3 skipped, 1 xfailed. Ruff check and format pass on the new test, and node --check main.js passes.
  • Merge against base: between the merge base and dev, only docs and the CHANGELOG changed. There is no narrowed CI matrix, reverted config floor or resurrected code. CI uses ubuntu-latest, which has Node, so the new test will run there instead of skipping.

Optional

  • The CHANGELOG headline ("IDs that are not CSS identifiers") claims more than the fix covers. IDs containing CR or NUL still produce no PDF item. The cause is captureDocumentFileData, which keys files by the parsed <strong> text, and this PR did not change it. This is not a regression. Narrowing the wording to "IDs that contain spaces or CSS punctuation" would be accurate.

Comment thread CHANGELOG.md Outdated

### Fixed

- **The HTML report's PDF viewer loads documents whose IDs are not CSS

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.

Blocker: this bullet conflicts with current dev. A trial git merge --no-commit origin/dev at 5745260 gives CONFLICT (content): Merge conflict in CHANGELOG.md, and that is the only conflicted file. dev (#478, via #550) added its own bullet at the same place under [Unreleased] > ### Fixed. Merge dev and keep both bullets. Until then GitHub blocks the merge and CI does not run on this PR.

Optional: "not CSS identifiers" is broader than the fix. IDs containing CR or NUL still produce no PDF item, through captureDocumentFileData (not touched here). "IDs that contain spaces or CSS punctuation" would be accurate.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

@vawsgit @sromoam Merged current dev (8c56dfa) in 35a9db4, no rebase. CHANGELOG.md keeps both dev bullets (#478 and the pretty-printer fix) and puts the PDF-viewer bullet after them. I also narrowed its headline to "IDs that contain spaces or CSS punctuation", as suggested.

On the merged tree: tests/reporting/html 184 passed; non-integration suite 4180 passed, 13 skipped, 1 xfailed; ruff check src tests clean. GitHub now reports the PR as mergeable.

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

✅ LGTM!

The only blocker from my previous review is fixed. Merge commit 35a9db4 resolved the CHANGELOG.md conflict with dev. The code is byte-identical to 5745260, which I already verified: git diff 5745260 35a9db4 -- src tests is empty.

Previous review (on 5745260)

  • Blocker, CHANGELOG.md conflicts with dev: fixed.
    • git merge-tree --write-tree origin/dev 35a9db4 reports no conflict. The merge base is the dev tip (8c56dfa).
    • The #478 bullet from dev is kept word for word. The "Pretty printers" bullet is kept too.
    • This PR's bullet sits under [Unreleased] > ### Fixed and still says Refs #476 with no closing keyword (CHANGELOG.md#L30-L37).
    • git diff origin/dev 35a9db4 --stat and the three-dot diff list the same 6 files. The merge dropped nothing from dev and added nothing extra.
  • Optional, the CHANGELOG headline claimed too much: fixed. The headline now reads "loads documents whose IDs contain spaces or CSS punctuation".
  • Correction to my previous review. I wrote that CI never ran because the merge ref could not be built. That was wrong. The workflow runs on 5745260 and 2b7c362 exist and show action_required: GitHub was waiting for a maintainer to approve workflows on this fork PR. The runs on 35a9db4 are in the same state.

What I verified (head 35a9db4, stickler imported from the PR worktree's src)

  • Node harness: dev's main.js fails 12/16 cases. Head fails 0/16. tests/reporting/html gives 184 passed.
  • Full suite (--extra llm --extra bert, Python 3.12.13): 4197 passed, 3 skipped, 1 xfailed.
  • Mutation tests, against all 16 harness cases:
    • Reverting the canvas, loading or error lookup fails 12/16 each.
    • Reverting the render-loading, page-info, prev or next lookup fails 6/16 each.
    • isEvalSupported: true fails 16/16, so the CVE-2024-4367 mitigation is pinned.
    • Removing the canvas display='block' fails 8/16.
  • Real browser: I generated a report with EvaluationHTMLReporter.generate_report(...) from a real 2-page PDF. I drove it in headless Chrome with PDF.js 3.11.174 and tried 15 document IDs. They included inv 001, a:b, a[b], a"b, 請求書, a\b, an ID containing U+2028, pdf-canvas-nested, and </script>, ');...(' and <img onerror> payloads.
    • Head: 15/15 loaded and paged to "Page 2 of 2". No injected code ran.
    • dev: 5/15 loaded. The others threw ... is not a valid selector or matched nothing.
  • No other selector built from a document ID remains in main.js. canvasId.replace('pdf-canvas-', '') replaces only the first match, so pdf-canvas-nested works.
  • Staleness against dev: no CI workflow changes, no reverted config, no resurrected code. The CHANGELOG entry sits under [Unreleased], not under the released 1.0.1.

Before merge

  • A maintainer must approve the four workflow runs on 35a9db4 (Run Tests, Code Quality, Check Documentation, Security Scan). They show action_required.

Non-blocking (low, still open)

  • The harness's fake getElementById finds elements that were never attached. Deleting pdfContainer.appendChild(navControls); still gives 0/16 failures, because appendChild registers the child globally whatever its parent is (pdf_document_ids.cjs#L9-L14).
  • tests/reporting/html/test_pdf_document_ids.py:16 reads main.js from the repo path, not from the copy the reporter embeds.

@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-18T23:16:52+00:00
  • Time since scan: 2 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-18T23:14:07+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 0 0 0 6745 0 0 PASSED 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 0 0 0 0 0 0 PASSED 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)

Report generated by Automated Security Helper (ASH) at 2026-11-18T23:16:53+00:00

@digalaviz
digalaviz merged commit 9fa8e29 into awslabs:dev Nov 18, 2026
11 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.

4 participants