diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-08-21 15:30:13 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-08-28 22:31:42 -0700 |
commit | d6d7c9620abddc5e5e45450c091bc8a73bac8f66 (patch) | |
tree | 2dd3e01150a5611f5bb86cd08239de7f5eca3106 /src/Text/Pandoc/App | |
parent | b76796eae8ce842f8414cca8cd8e3b55be513694 (diff) | |
download | pandoc-d6d7c9620abddc5e5e45450c091bc8a73bac8f66.tar.gz |
Add `--sandbox` option.
+ Add sandbox feature for readers. When this option is used,
readers and writers only have access to input files (and
other files specified directly on command line). This restriction
is enforced in the type system.
+ Filters, PDF production, custom writers are unaffected. This
feature only insulates the actual readers and writers, not
the pipeline around them in Text.Pandoc.App.
+ Note that when `--sandboxed` is specified, readers won't have
access to the resource path, nor will anything have access to
the user data directory.
+ Add module Text.Pandoc.Class.Sandbox, defining
`sandbox`. Exported via Text.Pandoc.Class. [API change]
Closes #5045.
Diffstat (limited to 'src/Text/Pandoc/App')
-rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 5 | ||||
-rw-r--r-- | src/Text/Pandoc/App/Opt.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/App/OutputSettings.hs | 22 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index d2c12573c..99017000a 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -188,6 +188,11 @@ options = (\opt -> return opt { optFileScope = True })) "" -- "Parse input files before combining" + , Option "" ["sandbox"] + (NoArg + (\opt -> return opt { optSandbox = True })) + "" + , Option "s" ["standalone"] (NoArg (\opt -> return opt { optStandalone = True })) diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs index d54d932b7..48eb15fdf 100644 --- a/src/Text/Pandoc/App/Opt.hs +++ b/src/Text/Pandoc/App/Opt.hs @@ -160,6 +160,7 @@ data Opt = Opt , optCSL :: Maybe FilePath -- ^ CSL stylesheet , optBibliography :: [FilePath] -- ^ Bibliography files , optCitationAbbreviations :: Maybe FilePath -- ^ Citation abbreviations + , optSandbox :: Bool } deriving (Generic, Show) instance FromYAML (Opt -> Opt) where @@ -595,6 +596,8 @@ doOpt (k',v) = do parseYAML v >>= \x -> return (\o -> o{ optEol = x }) "strip-comments" -> parseYAML v >>= \x -> return (\o -> o { optStripComments = x }) + "sandbox" -> + parseYAML v >>= \x -> return (\o -> o { optSandbox = x }) _ -> failAtNode k' $ "Unknown option " ++ show k -- | Defaults for command-line options. @@ -673,6 +676,7 @@ defaultOpts = Opt , optCSL = Nothing , optBibliography = [] , optCitationAbbreviations = Nothing + , optSandbox = False } parseStringKey :: Node Pos -> Parser Text diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs index 3f83f4b21..7b057713b 100644 --- a/src/Text/Pandoc/App/OutputSettings.hs +++ b/src/Text/Pandoc/App/OutputSettings.hs @@ -90,11 +90,31 @@ optToOutputSettings opts = do then writerName else T.toLower $ baseWriterName writerName + let makeSandboxed pureWriter = + let files = maybe id (:) (optReferenceDoc opts) . + maybe id (:) (optEpubMetadata opts) . + maybe id (:) (optEpubCoverImage opts) . + maybe id (:) (optCSL opts) . + maybe id (:) (optCitationAbbreviations opts) $ + optEpubFonts opts ++ + optBibliography opts + in case pureWriter of + TextWriter w -> TextWriter $ \o d -> sandbox files (w o d) + ByteStringWriter w + -> ByteStringWriter $ \o d -> sandbox files (w o d) + + (writer, writerExts) <- if ".lua" `T.isSuffixOf` format then return (TextWriter (\o d -> writeCustom (T.unpack writerName) o d), mempty) - else getWriter (T.toLower writerName) + else if optSandbox opts + then + case runPure (getWriter writerName) of + Left e -> throwError e + Right (w, wexts) -> + return (makeSandboxed w, wexts) + else getWriter (T.toLower writerName) let standalone = optStandalone opts || not (isTextFormat format) || pdfOutput |