Skip to content

Allow passing arbitrary CLI options to the engine on a per block-level basis #64

@kainctl

Description

@kainctl

As per the discussion in #62

My wish is to allow passing arbitrary CLI options to the engine on a per block-level basis.

The biggest concern is the introduction of security issues and is the reason why this option should be opt-in.
But I personally would like to clarify what security issues are introduced.

From the previous disucssion:

Is shell injection possible?

From my investigation in #62 (comment)

From my short investigation:

https://github.com/jgm/pandoc/blob/d4d69fafb9bc8034cd39e99dbe48b2545eba2d3f/src/Text/Pandoc/Process.hs#L45-L51

shows that System.Process.proc is used to call the process and that function in turn uses a
RawCommand https://hackage-content.haskell.org/package/process-1.6.26.1/docs/src/System.Process.html#proc.

Shell injection attacks like args = {; rm -rf /} should not happen.
I manually tested it and it doesn't cause any issues.

I believe that there would be no shell injection vector.

File exfiltration

In response @tarleb clarified that: #62 (comment)

My main security concern here is the overwriting of files and info exfiltration, as allowing arbitrary arguments would also allow control over the input and output files.

Where I am now wondering again if this is actually an issue.
As long as we pass in the input and output file options last and separate out positional arguments via -- I don't think that files could be arbitrarily written or read (assuming the CLI parsing of the engine works as expected).

For example with d2 if we have following tree:

.
├── example.d2
└── pawned.txt

and ensure that we append to the end with {'--', infile, outfile} there is no way to access pawned.txt.

See:

d2 pawned.txt -- example.d2 out.svg
# we automatically insert `--` plus our file args.
# output: err: bad usage: too many arguments passed
d2 -- pawned.txt -- example.d2 out.svg
# even if the user tries to inject `--` before it breaks the execution
# err: bad usage: too many arguments passed

But to re-iterate: I still think that it is a good idea to disable this feature by default to be sure. I just want to provide some context and show that it isn't as bad as it may seem. If I would read the diagram.lua documentation and saw that this option enables a potential exploit I would probably be "scared" to use it. IMHO it would be nice to show how or when such as exploits could happen. But maybe this is just my view. And I could understand if we should default to "scary warnings" and maybe just document it in the code for the interested users. 🤷

Implementation

Before either @cparadis6191 or I implement the feature, I would like to hear where you (@tarleb) would like to have the additional options. Do you have any additional experience maybe with pandoc quirks? Or would you first like to see an option

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions