Skip to content

change reporting usage of handlebars to @kbn/handlebars#217778

Merged
pmuellr merged 5 commits intoelastic:mainfrom
pmuellr:fix-reporting-handlebars-usage
Apr 29, 2025
Merged

change reporting usage of handlebars to @kbn/handlebars#217778
pmuellr merged 5 commits intoelastic:mainfrom
pmuellr:fix-reporting-handlebars-usage

Conversation

@pmuellr
Copy link
Copy Markdown
Contributor

@pmuellr pmuellr commented Apr 10, 2025

Summary

Change reporting's usage of handlebars to @kbn/handlebars. Also added a test to ensure user input is HTML escaped (it always has been, this just tests it).

There should be no change to the final rendered output, at all. These changes only affect PDF and PNG reports, not CSV reports.

Checklist

Check the PR satisfies following conditions.

  • still renders the title in the page header
  • when "PDF footer image" is set in Advanced Settings, it's rendered in the footer; also rendered will be Powered by Elastic beneath it
  • when "PDF footer image" is NOT set in Advanced Settings, the default icon is rendered in the footer; Powered by Elastic will not be rendered.

Reviewers should verify this PR satisfies this list as well.

@pmuellr pmuellr added Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// Feature:Reporting:Framework Reporting issues pertaining to the overall framework Feature:Reporting:Screenshot Reporting issues pertaining to PNG/PDF file export labels Apr 10, 2025
@pmuellr pmuellr marked this pull request as ready for review April 10, 2025 10:18
@pmuellr pmuellr requested a review from a team as a code owner April 10, 2025 10:18
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@pmuellr pmuellr added backport:all-open Backport to all branches that could still receive a release release_note:skip Skip the PR/issue when compiling release notes labels Apr 10, 2025
async function compileTemplate<T>(pathToTemplate: string): Promise<TemplateDelegate<T>> {
const contentsBuffer = await fs.readFile(pathToTemplate);
return Handlebars.compile(contentsBuffer.toString());
return Handlebars.compileAST(contentsBuffer.toString());
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.

question: can we limit helpers in this context?

  return Handlebars.compileAST(contentsBuffer.toString(), { knownHelpersOnly: true });

and maybe even?

  return Handlebars.compileAST(contentsBuffer.toString(), { knownHelpers: { set all not needed built-in helpers to `false`}, knownHelpersOnly: true });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suspect we can, since the HB usage here is pretty simple. Simple variable usage, and and #if block/section.

I'm unfamiliar with these options though, so ... any advice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just committed this - 69dd2d7 - locking down everything but #if - and it seems to do everything correctly.

@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 10, 2025

I tested PNG, PDF, and PDF "for print" - there's a problem with PDF "for print" which I suspect is unrelated. (it is a known problem: https://github.com/elastic/response-ops-team/issues/310 )

The other two, the titles work fine, and for PDF setting the footer image in Advanced Settings works fine - renders the image and the "Powered by Elastic" copy.

@pmuellr pmuellr added ci:project-deploy-elasticsearch Create an Elasticsearch Serverless project ci:cloud-deploy Create or update a Cloud deployment labels Apr 10, 2025
@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 10, 2025

/ci

@pmuellr pmuellr removed the ci:project-deploy-elasticsearch Create an Elasticsearch Serverless project label Apr 11, 2025
@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 15, 2025

@elasticmachine merge upstream

@pmuellr pmuellr requested a review from azasypkin April 15, 2025 14:29
Copy link
Copy Markdown
Contributor

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks good from a security perspective, thanks for tightening down Handlebars compile options!

Copy link
Copy Markdown
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM

Tested the code using a Docker container, no regressions.

@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 16, 2025

@elasticmachine merge upstream

@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 28, 2025

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 28, 2025

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #51 / saved objects tagging - functional tests maps integration listing allows to manually type tag filter query

Metrics [docs]

✅ unchanged

History

@pmuellr pmuellr merged commit 3b5e96a into elastic:main Apr 29, 2025
10 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 7.17, 8.17, 8.18, 8.19, 9.0

https://github.com/elastic/kibana/actions/runs/14730841139

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.

(cherry picked from commit 3b5e96a)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.

(cherry picked from commit 3b5e96a)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.

(cherry picked from commit 3b5e96a)
@kibanamachine
Copy link
Copy Markdown
Contributor

💔 Some backports could not be created

Status Branch Result
7.17 Backport failed because of merge conflicts

You might need to backport the following PRs to 7.17:
- chore(deps): bump formidable from to 3.5.2 to 3.5.4 (#219385)
8.17 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.17:
- [ResponseOps][Cases]Allow dashes in host names in Observables (#219038)
- [Security Solution] Add new fields to indices metadata (#219246)
- [Synthetics]: Fixed monitor status rule control (#218994)
8.18
8.19
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 217778

Questions ?

Please refer to the Backport tool documentation

pmuellr added a commit to pmuellr/kibana that referenced this pull request Apr 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.

(cherry picked from commit 3b5e96a)

# Conflicts:
#	x-pack/plugins/screenshotting/server/browsers/chromium/templates/index.test.ts
pmuellr added a commit to pmuellr/kibana that referenced this pull request Apr 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.

(cherry picked from commit 3b5e96a)

# Conflicts:
#	x-pack/platform/plugins/shared/screenshotting/server/browsers/chromium/templates/index.ts
#	x-pack/platform/plugins/shared/screenshotting/tsconfig.json
@pmuellr
Copy link
Copy Markdown
Contributor Author

pmuellr commented Apr 29, 2025

💚 All backports created successfully

Status Branch Result
8.17
7.17

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 29, 2025
…217778) (#219527)

# Backport

This will backport the following commits from `main` to `8.19`:
- [change reporting usage of `handlebars` to `@kbn/handlebars`
(#217778)](#217778)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Patrick
Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2025-04-29T12:08:28Z","message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:all-open","ci:cloud-deploy","Feature:Reporting:Framework","Feature:Reporting:Screenshot","v9.1.0"],"title":"change
reporting usage of `handlebars` to
`@kbn/handlebars`","number":217778,"url":"https://github.com/elastic/kibana/pull/217778","mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217778","number":217778,"mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}}]}]
BACKPORT-->

Co-authored-by: Patrick Mueller <patrick.mueller@elastic.co>
kibanamachine added a commit that referenced this pull request Apr 29, 2025
…17778) (#219528)

# Backport

This will backport the following commits from `main` to `9.0`:
- [change reporting usage of `handlebars` to `@kbn/handlebars`
(#217778)](#217778)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Patrick
Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2025-04-29T12:08:28Z","message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:all-open","ci:cloud-deploy","Feature:Reporting:Framework","Feature:Reporting:Screenshot","v9.1.0"],"title":"change
reporting usage of `handlebars` to
`@kbn/handlebars`","number":217778,"url":"https://github.com/elastic/kibana/pull/217778","mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217778","number":217778,"mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}}]}]
BACKPORT-->

Co-authored-by: Patrick Mueller <patrick.mueller@elastic.co>
kibanamachine added a commit that referenced this pull request Apr 29, 2025
…217778) (#219526)

# Backport

This will backport the following commits from `main` to `8.18`:
- [change reporting usage of `handlebars` to `@kbn/handlebars`
(#217778)](#217778)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Patrick
Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2025-04-29T12:08:28Z","message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:all-open","ci:cloud-deploy","Feature:Reporting:Framework","Feature:Reporting:Screenshot","v9.1.0"],"title":"change
reporting usage of `handlebars` to
`@kbn/handlebars`","number":217778,"url":"https://github.com/elastic/kibana/pull/217778","mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217778","number":217778,"mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}}]}]
BACKPORT-->

Co-authored-by: Patrick Mueller <patrick.mueller@elastic.co>
pmuellr added a commit that referenced this pull request Apr 29, 2025
…217778) (#219543)

# Backport

This will backport the following commits from `main` to `8.17`:
- [change reporting usage of `handlebars` to `@kbn/handlebars`
(#217778)](#217778)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Patrick
Mueller","email":"patrick.mueller@elastic.co"},"sourceCommit":{"committedDate":"2025-04-29T12:08:28Z","message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:all-open","ci:cloud-deploy","Feature:Reporting:Framework","Feature:Reporting:Screenshot","v9.1.0"],"title":"change
reporting usage of `handlebars` to
`@kbn/handlebars`","number":217778,"url":"https://github.com/elastic/kibana/pull/217778","mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217778","number":217778,"mergeCommit":{"message":"change
reporting usage of `handlebars` to `@kbn/handlebars` (#217778)\n\nChange
reporting's usage of `handlebars` to `@kbn/handlebars`. Also\nadded a
test to ensure user input is HTML escaped (it always has been,\nthis
just tests it).\n\nThere should be no change to the final rendered
output, at all. These\nchanges only affect PDF and PNG reports, not CSV
reports.","sha":"3b5e96a4b8dc3d2741de658ea9ad7981617fe3db"}},{"url":"https://github.com/elastic/kibana/pull/219526","number":219526,"branch":"8.18","state":"OPEN"},{"url":"https://github.com/elastic/kibana/pull/219527","number":219527,"branch":"8.19","state":"OPEN"},{"url":"https://github.com/elastic/kibana/pull/219528","number":219528,"branch":"9.0","state":"OPEN"}]}]
BACKPORT-->
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Apr 30, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.
legrego pushed a commit to legrego/kibana that referenced this pull request Jun 11, 2025
…217778)

Change reporting's usage of `handlebars` to `@kbn/handlebars`. Also
added a test to ensure user input is HTML escaped (it always has been,
this just tests it).

There should be no change to the final rendered output, at all. These
changes only affect PDF and PNG reports, not CSV reports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:all-open Backport to all branches that could still receive a release ci:cloud-deploy Create or update a Cloud deployment Feature:Reporting:Framework Reporting issues pertaining to the overall framework Feature:Reporting:Screenshot Reporting issues pertaining to PNG/PDF file export release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.17.6 v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants