highcharts / node-export-server

Highcharts Node.js export server
Other
356 stars 260 forks source link

Highcharts.AST.allowedAttributes #533

Open Pascal76 opened 5 months ago

Pascal76 commented 5 months ago

Hello,

How can I use Highcharts.AST.allowedAttributes with /usr/local/bin/highcharts-export-server (v4) please ?

I tryed using --customCode "AST.allowedAttributes.js" but it does not work.

The file contains: Highcharts.AST.allowedAttributes.push('border'); Highcharts.AST.allowedAttributes.push('align'); Highcharts.AST.allowedAttributes.push('bordercolor'); Highcharts.AST.allowedAttributes.push('zIndex'); Highcharts.AST.allowedAttributes.push('bgcolor'); Highcharts.AST.allowedAttributes.push('cellpadding'); Highcharts.AST.allowedAttributes.push('cellspacing'); Highcharts.AST.allowedTags.push('center'); Highcharts.AST.allowedAttributes.push('center');

On the Dockerfile: WORKDIR /node-export-server ADD ["AST.allowedAttributes.js","/node-export-server"] RUN chown -R node /node-export-server && \ chmod 644 AST.allowedAttributes.js

The command line : /bin/docker run -u 0:0 -v /apache_sites/jbm:/apache_sites/jbm --rm --tmpfs=/run highcharts_es timeout 10 /usr/local/bin/highcharts-export-server --allowCodeExecution true --infile /apache_sites/jbm/b.json --outfile /apache_sites/jbm/web/img/toto.png --resources '[]' --customCode AST.allowedAttributes.js --width 720 --height 320 --scale 1.2 --logLevel 4

jszuminski commented 5 months ago

Thanks for reporting @Pascal76!

Here's a sample showing how to use the customCode option:

https://github.com/highcharts/node-export-server/blob/ced7b17b8e2188291ba90d5d56acc440f71024e1/tests/http/scenarios/allow_code_execution.json#L1-L23

The customCode option accepts either stringified JavaScript code or the name of the .js file available locally.

You can take a look at the CLI examples as well: https://github.com/highcharts/node-export-server/blob/ced7b17b8e2188291ba90d5d56acc440f71024e1/tests/cli/scenarios/allow_code_execution_and_file_resources.json#L1-L8

Please try to follow this and let me know if it works for you. If not, please share the full log (--logLevel 4). Try to include a console.log statement in your customCode as well, it will help us determine whether your function runs or not.

Pascal76 commented 5 months ago

Thank you !

It works except for the border attribute (?!) while my JS file contains :

Highcharts.AST.allowedTags.push('table'); Highcharts.AST.allowedTags.push('tr'); Highcharts.AST.allowedTags.push('td'); Highcharts.AST.allowedTags.push('center'); Highcharts.AST.allowedTags.push('class'); Highcharts.AST.allowedTags.push('style'); Highcharts.AST.allowedAttributes.push('border'); Highcharts.AST.allowedAttributes.push('align'); Highcharts.AST.allowedAttributes.push('bordercolor'); Highcharts.AST.allowedAttributes.push('zIndex'); Highcharts.AST.allowedAttributes.push('bgcolor'); Highcharts.AST.allowedAttributes.push('cellpadding'); Highcharts.AST.allowedAttributes.push('cellspacing'); Highcharts.AST.allowedAttributes.push('center');

What is not working : 'name' : 'outlook

',

When I remove border=0 then it works.

jszuminski commented 5 months ago

That is indeed strange.

Could you please share the SVG that you're sending? Is there a way for me to replicate this locally?

Pascal76 commented 5 months ago

b.json AST.allowedAttributes.js.txt toto

Pascal76 commented 5 months ago

also if the json file contains comments like // xx then it breaks the generation of the image ( / xx / format is OK )

Wed Jun 05 2024 12:28:02 GMT+0200 [error] - [pool] In pool.postWork: Error encountered during export: 6.174512ms. SyntaxError: Unexpected token ')' new Function () at triggerExport (evaluate at setAsConfig (file:///node-export-server/lib/export.js:138:8), :68:6) at #evaluate (file:///node-export-server/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:373:19) at async ExecutionContext.evaluate (file:///node-export-server/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/ExecutionContext.js:268:16) at async IsolatedWorld.evaluate (file:///node-export-server/node_modules/puppeteer-core/lib/esm/puppeteer/cdp/IsolatedWorld.js:96:16) at async CdpFrame.evaluate (file:///node-export-server/node_modules/puppeteer-core/lib/esm/puppeteer/api/Frame.js:339:20) at async CdpPage.evaluate (file:///node-export-server/node_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:796:20) at async default (file:///node-export-server/lib/export.js:188:9) at async postWork (file:///node-export-server/lib/pool.js:307:20) at async doExport (file:///node-export-server/lib/chart.js:439:20) at async Object.singleExport (file:///node-export-server/lib/chart.js:208:3)

jszuminski commented 4 months ago

@Pascal76 the JSON file cannot contain comments: https://stackoverflow.com/questions/244777/can-comments-be-used-in-json

If the provided JSON file is not proper, there will be an error (most likely) which would resemble the one that you've attached above.

Regarding the allowed tags & attributes, I will investigate why that happens.

jszuminski commented 3 months ago

Closing due to inactivity.


Summary:

Pascal76 commented 3 months ago

Hello @jszuminski You closed this ticket... but did you check "Regarding the allowed tags & attributes, I will investigate why that happens." ?

Pascal76 commented 2 months ago

I spoke about issue with border=0 Same issue with align="XXX" Even when AST.allowedAttributes.js (loaded by 'customCode' : './AST.allowedAttributes.js') contains : Highcharts.AST.allowedAttributes.push('align');