Skip to content

Render local resources in converting PDF by --allow-local-files option #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2018

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Sep 4, 2018

This PR will support rendering local resources in converting PDF by added --allow-local-files option. See yhatt/marp#242.

marp slide.md --pdf --allow-local-files

So far, we have rendered the converted HTML through data URI while converting into PDF. It is secure and less file I/O, but cannot access to file:/// scheme resources.

By enabling this option, we will create a temporally HTML file and use to render. It has file:/// scheme and can access to local files by reason of Same-Origin Policy.

To resolve relative path in Markdown, we will add <base> element to template while converting PDF.

Example

<!-- inline + relative path -->
![](marp.png)

<!-- background + absolute path -->
![bg right](/Users/yuki.hattori/yhatt.png)
--pdf --pdf --allow-local-files
(empty slide) Render local resources correctly

⚠️ Security

For security reason, local file access is disabled by default. You have to specify option explicitly if you want to use local resources. You would see a warning on CLI when using the option.

You should never use --allow-local-files if you want to use marp-cli for purpose of server-side rendering. The exploited Markdown could access/leak unexpected server files.

Especially --html --allow-local-files on a server is a nightmare!!

😈 Worst case

# Don't try this at server.
echo '<iframe src="/etc/passwd"></iframe>' | marp -o DANGER.pdf --html --allow-local-files

An execution confirmed by user is OK at all (e.g. execute in your local terminal).

@yhatt yhatt merged commit 3711151 into master Sep 4, 2018
@yhatt yhatt deleted the base-path branch September 4, 2018 09:43
@yhatt yhatt mentioned this pull request May 15, 2019
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.

1 participant