Skip to content

Commit a46bd0d

Browse files
authored
Make user aware of the risk of using qqx (#3696)
* Add `qqx` example to warn user about the possiblity of arbitrary code execution * * Add `qqx` section in traps * warns user about `qqx` in quoting * Fix Typos
1 parent e80c96d commit a46bd0d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

doc/Language/quoting.pod6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ Again, the output of the external command can be kept in a variable:
513513
# runs the command: grep -i cool /usr/share/dict/words
514514
say $output; # OUTPUT: «Cooley␤Cooley's␤Coolidge␤Coolidge's␤cool␤...»
515515
516+
Be aware of the content of the Raku variable used within an external command; malicious content can be used to execute arbitrary code. See L<C<qqx> traps|/language/traps/Beware_of_variables_used_within_qqx>
517+
516518
See also L<run|/routine/run> and L<Proc::Async|/type/Proc::Async> for
517519
better ways to execute external commands.
518520

doc/Language/traps.pod6

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,17 @@ my $a = 1;
644644
say Q:c«{$a}()$b()»;
645645
# OUTPUT: «1()$b()␤»
646646
647+
=head2 Beware of variables used within C<qqx>
648+
649+
Variables within C<qqx[]> can introduce a security hole; the variable content can be set to well-crafted string and execute arbitrary code:
650+
651+
=for code
652+
my $world = "there\";rm -rf /path/to/dir\"";
653+
say qqx{echo "hello $world"};
654+
# OUTPUT: «hello there␤»
655+
656+
The above code will also delete I</path/to/dir>, you can avoid this problem by making sure the variable content does not have shell special characters, or use L<run|/routine/run> and L<Proc::Async|/type/Proc::Async> for better ways to execute external commands.
657+
647658
=head2 Strings are not iterable
648659
649660
There are methods that L<Str|/type/Str> inherits from L<Any|/type/Any> that work

0 commit comments

Comments
 (0)