-
Notifications
You must be signed in to change notification settings - Fork 47
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
Issue with perl in Tainted mode #106
Comments
You should pass absolute path(and untainted) both
https://metacpan.org/pod/Text::Xslate#Text::Xslate-new-options |
Those two variables were already untainted absolute paths, and I did an additional untainting using a dumb regex (/.*/), just to be 100% sure. If they weren't I would get errors when using any template. The issue don't happen when a template with no includes is used and the template is changed. Only when an included one is changed. It seems that the included template path (like in [% INCLUDE "another_template.tpl" %]) is not properly untainted when extracted to be used in dangerous operations, like the unlink from the cache when it's outdated. |
Could you show us code and templates(as small as possible) which reproduce this issue ? |
Sure! |
It's done. |
Please paste here(if they are not too large)or update gist or somewhere, |
I uploaded the test to: http://bruno.arqs.com.br/perl/text_xslate_issue_taintmode_test.zip Just update the paths inside the script to match those of your system. I just run this test on 3 servers I have and it failed on the second run on all 3. |
I made an additional test here using Kolon syntax, and the same thing happens. |
After some time doing a little debugging I found a place where it breaks. In the file Text/Xslate.pm I made a quick hack to test if the $file was tainted, and to no surprise it was, confirming my suspicions. sub load_file {
my($self, $file, $mtime, $omit_augment) = @_;
local $self->{omit_augment} = $omit_augment;
print STDERR "Tainted file name: $file\n" if (Scalar::Util::tainted($file));
($file) = ($file =~ /(.*)/s); When run with the test script it issues the warning to STDERR and processes the template normally after the dirty untainting. |
Any news on this? |
Sorry, it makes no progress. Would it be possible to disable taint mode for the files which uses including template ? I think |
Unfortunately, I can't disable taint mode in the app i'm using Xslate. I have a question: is the $file parameter in load_file already sanitized upon being called? Thinking about it further, might be happening the following problem: In that case, the catchall regex is harmless and solves the problem. I've found only those spots that call load_file:
The $file parameter in load_file comes from the return of _bare_to_file in the Compiler.pm:
|
I'm currently migrating one of our systems that runs on Template::Toolkit to Text::Xslate (version 3.1.2) with TTerse syntax and I think that I found a little bug when running on tainted mode perl.
It happens in the following case:
TemplateA (includes TemplateB)
TemplateB
If I change the content of TemplateB file and generate new content with TemplateA, perl throws the following error:
Here is the code snippet of Xslate.pm that throws the error:
Seems that the $cachepath variable of include statements are not untainted, thus the error. Right now I don't know if it's only related to TTerse syntax or the others too. I'll make some test scripts to help investigate this.
The text was updated successfully, but these errors were encountered: