SEC: Blacklist tex and pgf preambles in style files#31249
SEC: Blacklist tex and pgf preambles in style files#31249scottshambaugh wants to merge 1 commit intomatplotlib:mainfrom
Conversation
1079f5d to
519b3cd
Compare
|
This would break third-parties like https://github.com/garrettj403/SciencePlots which explicitly rely on those settings being available in style files. |
|
The other approach to take is to sanitize the input so that shell escaping
is not possible.
…On Tue, Mar 10, 2026 at 5:19 AM Antony Lee ***@***.***> wrote:
*anntzer* left a comment (matplotlib/matplotlib#31249)
<#31249 (comment)>
This would break third-parties like
https://github.com/garrettj403/SciencePlots which explicitly rely on
those settings being available in style files.
I have argued elsewhere that I don't believe in neither the style file
system (they should just be python modules that expose a rcparams_update
dict or function) nor the security model around them (ipython is happy with
plain executable config files), so I don't think I can really judge this,
because I simply don't understand the point.
—
Reply to this email directly, view it on GitHub
<#31249 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6CPCBPZ4E3YBOQ7QB34P7M2BAVCNFSM6AAAAACWKBQFOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DAMRZHA2DIOJQGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
I would be curious how you could do that, given that |
|
Ouch, right. And it would not be practical to ban `\usepackage`
because that would basically negate the purpose of the preamble. What
about explicitly disabling shell escaping? I'm not familiar enough
with latex and the pgf stuff to know if that is even possible.
…On Tue, Mar 10, 2026 at 7:51 AM Antony Lee ***@***.***> wrote:
anntzer left a comment (matplotlib/matplotlib#31249)
I would be curious how you could do that, given that \usepackage{foo} can basically run anything (whatever is in foo.sty, including \write18-based tex shell escapes).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
|
I do not think this is currently exploitable. Per https://latexref.xyz/_005cwrite18.html (TBD is that is the best reference) and https://latexref.xyz/Command-line-options.html (which matches the help on my machine) there is no ENV to control this and to enable shell commands you must pass matplotlib/lib/matplotlib/texmanager.py Lines 301 to 303 in c722367 matplotlib/lib/matplotlib/backends/backend_pgf.py Lines 283 to 286 in c722367 matplotlib/lib/matplotlib/rcsetup.py Line 1374 in c722367 In principle someone could add their own Per all of that, I do not think we need to make this change. I think the main thing we should explicitly add I tested that if you add flags to turn it off and on then the last one wins so even if the user has gone and made an alias/helper that turns it on, we will still turn it off unless they go to the effort processing the command line arguments to eject the We may also want to add a |
tacaswell
left a comment
There was a problem hiding this comment.
See long comment. I do not think this is exploitable as we invoke the latex that processes the tex file the preable is injected into and we do not turn on shell escaping so latex should not do any shell calls, thus this is not actually exploitable.
|
If I am wrong about the above, then we need to find a better way to handle the |
|
The issue is that default shell access can be set as a system level config, and we don't control that. That's set by "In principle someone could add their own latex to the PATH " - I'm not really following this? We don't package our own latex? I like the idea of solving this by putting |
|
Ok, now knowing that there in (justification for the above) Polling the two distros I have easy access to (arch and RHEL9), the they both have with slightly different allowed programs DetailsThis may also be TeX Live 2026 vs TeX Live 2020 in the system install texmf.cnf. It looks like the upstream base configuration file is https://github.com/TeX-Live/texlive-source/blob/51b51010d300bb364325471fc1d72d85f7b2430f/texk/kpathsea/texmf.cnf#L634-L639 which is also set to So my analysis is changed a bit in that currently a user or a packager could have set things up in a way to make this exploitable, but they would have had to intentionally do that. We do not want to drop the preamble as it is useful (and we have at least one know use in the wild), but we do want to force details on why the above is not complete too-clever-user proof I mean if someone drops an executable called latex in their path with the contents #!/bin/bash
exec latex --shell-escape "$@"or the pathological version #!/bin/bash
args=()
for arg in "$@"; do
[[ "$arg" == "--no-shell-escape" ]] && continue
args+=("$arg")
done
exec latex --shell-escape "${args[@]}"(to make these really work you would have find the actual real latex, but that is left as an exercise for those making poor life choices) someplace in the system PATH ahead of real latex (I know the *nix way of doing this, I understand it is different in windows, but nothing past that), then they can control what cli flags latex sees and force escaping to happen. But from a security point of view, if the attacker can already write files to disk and modify $PATH, then they already have the ability to write files and modify the $PATH which makes doing so via injecting arbitrary code into the preamble redundant. And if the user is this dedicated to making arbitrary shell work in their preamble I wish them good luck 🤣 . |
|
Shell escape changes opened in #31282 IMO that's enough to keep the preamble and close this PR. That still leaves open the possibility of reading / writing files, but not arbitrary code execution afaict. The default Yeah, I don't think covering for PATH modifications is a meaningful security goal. A malicious matplotlibrc file is already a bit of a stretch since it requires a download, but is more plausibly overlooked as a risk. |
|
Talked on the call today and agreed that the |
PR summary
Style files can currently set
text.latex.preambleandpgf.preamble, which are interpolated verbatim into LaTeX documents. A malicious style file could inject arbitrary LaTeX commands, including\write18for shell execution on TeX distributions with shell-escape enabled.This adds both params to
_STYLE_BLACKLISTso they are ignored when loading style files. Users can still set them via rcParams directly. Their entries inclassic.mplstylewere empty, and removed.test_up_to_date_blacklistexercises the blacklist to ensure it's functional.AI Disclosure
Claude was used to run the audit. Code manually reviewed
PR checklist