Skip to content

Commit c9eec10

Browse files
authored
Build: escape all whitespaces (#12152)
ref https://readthedocs.slack.com/archives/C04SS8XNB6K/p1746136083159309 NOTE: this isn't a vulnerability, as all commands that make use of this function are run inside a container.
1 parent 33596f9 commit c9eec10

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class DockerBuildCommand(BuildCommand):
282282
"""
283283

284284
bash_escape_re = re.compile(
285-
r"([\t\ \!\"\#\$\&\'\(\)\*\:\;\<\>\?\@\[\\\]\^\`\{\|\}\~])" # noqa
285+
r"([\s\!\"\#\$\&\'\(\)\*\:\;\<\>\?\@\[\\\]\^\`\{\|\}\~])" # noqa
286286
)
287287

288288
def __init__(self, *args, escape_command=True, **kwargs):

readthedocs/doc_builder/tests/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from django.test import TestCase
2+
3+
from readthedocs.doc_builder.environments import DockerBuildCommand
4+
5+
6+
class TestDockerBuildEnvironment(TestCase):
7+
def test_command_escape(self):
8+
commands = [
9+
(
10+
["ls", ".", "; touch /tmp/test"],
11+
"/bin/sh -c 'ls . \\;\\ touch\\ /tmp/test'",
12+
),
13+
(
14+
["ls", ".", "\ntouch /tmp/test"],
15+
"/bin/sh -c 'ls . \\\ntouch\\ /tmp/test'",
16+
),
17+
(
18+
["ls", ".", "\ftouch /tmp/test"],
19+
"/bin/sh -c 'ls . \\\ftouch\\ /tmp/test'",
20+
),
21+
(
22+
["ls", ".", "\ttouch /tmp/test"],
23+
"/bin/sh -c 'ls . \\\ttouch\\ /tmp/test'",
24+
),
25+
(
26+
["ls", ".", "\vtouch /tmp/test"],
27+
"/bin/sh -c 'ls . \\\vtouch\\ /tmp/test'",
28+
),
29+
]
30+
for command, expected in commands:
31+
build_command = DockerBuildCommand(command=command)
32+
assert build_command.get_wrapped_command() == expected, command

0 commit comments

Comments
 (0)