Skip to content

Hardening suggestions for jtd-codebuild / revert-3-pixeebot/drip-2024-02-17-pixee-python/subprocess-shell-false #6

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions jtd_codebuild/generators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
from typing import Dict, Any, AnyStr, List
from ..utils import safe_mkdir
from security import safe_command


class JTDCodeGenerator:
Expand Down Expand Up @@ -66,10 +67,8 @@ def generate(
target_language = target["language"]
target_path = self.get_target_path(target)
safe_mkdir(target_path)
process = subprocess.Popen(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

Copy link
Author

Choose a reason for hiding this comment

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

Replaces subprocess.{func} with more secure safe_command library functions.

self._codegen_command(self.schema_path, target_path, target_language),
shell=True,
stdout=subprocess.PIPE,
process = safe_command.run(subprocess.Popen, self._codegen_command(self.schema_path, target_path, target_language),
shell=False, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return [process]
7 changes: 3 additions & 4 deletions jtd_codebuild/generators/typescript_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Dict, Any, AnyStr, List
from ..utils import wait_for_processes
from .generator import JTDCodeGenerator
from security import safe_command


class JTDCodeGeneratorTypescriptTarget(JTDCodeGenerator):
Expand All @@ -19,10 +20,8 @@ def _compile_typescript(self, tsconfig_path: str) -> subprocess.Popen:
Args:
tsconfig_path: The path to the tsconfig.json file.
"""
return subprocess.run(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

Copy link
Author

Choose a reason for hiding this comment

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

Replaces subprocess.{func} with more secure safe_command library functions.

f"tsc --project {tsconfig_path}",
shell=True,
stdout=subprocess.PIPE,
return safe_command.run(subprocess.run, f"tsc --project {tsconfig_path}",
shell=False, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

Expand Down
3 changes: 1 addition & 2 deletions jtd_codebuild/tests/test_example_project_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def test_example_project_1():
# Run the command
subprocess.check_call(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

"jtd-codebuild fixtures/example_project_1",
shell=True,
cwd=cwd,
shell=False, cwd=cwd,
)

# Check the output
Expand Down
3 changes: 1 addition & 2 deletions jtd_codebuild/tests/test_example_project_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_example_project_2():
# Run the command
subprocess.check_call(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

"jtd-codebuild fixtures/example_project_2",
shell=True,
cwd=cwd,
shell=False, cwd=cwd,
)

# Check the output
Expand Down
3 changes: 1 addition & 2 deletions jtd_codebuild/tests/test_example_project_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_example_project_3():
# Run the command
subprocess.check_call(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

"jtd-codebuild fixtures/example_project_3",
shell=True,
cwd=cwd,
shell=False, cwd=cwd,
)

# Check the output
Expand Down
3 changes: 1 addition & 2 deletions jtd_codebuild/tests/test_example_project_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_example_project_4():
# Run the command
subprocess.check_call(
Copy link
Author

Choose a reason for hiding this comment

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

Set shell keyword argument to False

"jtd-codebuild fixtures/example_project_4",
shell=True,
cwd=cwd,
shell=False, cwd=cwd,
)

# Check the output
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy