Skip to content

allow stylesheets to read and write files in the site directory#1951

Open
xworld21 wants to merge 1 commit into
brucemiller:masterfrom
xworld21:exsl-document-site-directory
Open

allow stylesheets to read and write files in the site directory#1951
xworld21 wants to merge 1 commit into
brucemiller:masterfrom
xworld21:exsl-document-site-directory

Conversation

@xworld21
Copy link
Copy Markdown
Contributor

@xworld21 xworld21 commented Aug 31, 2022

Small functionality & security improvement, while working on #1948: stylesheets can read (via document()) and write (via <exsl:document>) files. This PR ensures that read/write operations happen in the site directory.

For security, operations are also restricted to the site directory, and network access is disabled.

Edit: this fixes #2053 in so far as letting exsl:document() write files in the correct place. My sandbox question in #2053 should rather be part of #2218.

Comment thread lib/LaTeXML/Post/XSLT.pm Outdated
Comment thread lib/LaTeXML/Post/XSLT.pm Outdated
Comment thread lib/LaTeXML/Post/XSLT.pm Outdated
Comment thread lib/LaTeXML/Post/XSLT.pm Outdated
@xworld21
Copy link
Copy Markdown
Contributor Author

xworld21 commented Jan 7, 2024

I have removed the libxslt security callback stuff, and kept this PR at a minimum: the point is, XSLT.pm is supposed to run in the site directory, because stylesheets can create additional files via exsl:document() (that could be very convenient to generate additional manifests, search indexes, custom EPUB tocs, etc). Simply changing directory is not controversial, I hope.

The security callbacks will reappear in the --recorder PR.

@dginev dginev requested a review from brucemiller March 31, 2025 12:31
@dginev
Copy link
Copy Markdown
Collaborator

dginev commented Mar 31, 2025

High-level question to @brucemiller : should LaTeXML's XSLT framework use exsl:document() ?

Comment thread lib/LaTeXML/Post/XSLT.pm
Comment on lines +81 to +87
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
pathname_chdir($destdir);

my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));

pathname_chdir($orig_cwd);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest a defensive check that the change is needed / well-defined:

Suggested change
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
pathname_chdir($destdir);
my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));
pathname_chdir($orig_cwd);
my $destdir = $doc->getDestinationDirectory;
my $orig_cwd = pathname_cwd();
my $needs_cwd_change = ($destdir ne $orig_cwd) && (-d $destdir);
pathname_chdir($destdir) if $needs_cwd_change;
my $newdoc = $doc->new($$self{stylesheet}->transform($doc->getDocument, %params));
pathname_chdir($orig_cwd) if $needs_cwd_change;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should also canonicalise the paths (especially if mixed path separators are involved) and emit an error/fatal if chdir fail.

@xworld21
Copy link
Copy Markdown
Contributor Author

should LaTeXML's XSLT framework use exsl:document() ?

Since this PR is under attention again, I should clarify the intention here, and split @dginev's question into two parts:

  • Should LaTeXML use exsl:document for auxiliary files (e.g. EPUB manifest)? Tricky proposition, because the generated files go directly to disk, bypassing the postprocessing pipeline.
  • Should LaTeXML support users that want to call exsl:document? This could be useful in e.g. BookML to generate search indices (not the best example, but you get my point I hope).

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.

sandbox document() and <exsl:document>

2 participants