-
Notifications
You must be signed in to change notification settings - Fork 354
Fix shell injection in rez-build process #1979
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
Open
JeanChristopheMorinPerso
wants to merge
5
commits into
AcademySoftwareFoundation:main
Choose a base branch
from
JeanChristopheMorinPerso:fix_shell_injection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−15
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab891ed
Fix shell injection in rez-build process caused by non-sanitized stri…
JeanChristopheMorinPerso 7d37c86
Add more quoting
JeanChristopheMorinPerso 5a04080
Add a test
JeanChristopheMorinPerso 07ef28f
Merge branch 'main' into fix_shell_injection
JeanChristopheMorinPerso 447b9cb
Fix test
JeanChristopheMorinPerso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,18 @@ | |
test the build system | ||
""" | ||
from rez.config import config | ||
from rez.build_process import create_build_process | ||
from rez.build_system import create_build_system | ||
from rez.build_process import create_build_process, BuildType | ||
from rez.build_system import create_build_system, BuildSystem | ||
from rez.resolved_context import ResolvedContext | ||
from rez.exceptions import BuildError, BuildContextResolveError, \ | ||
PackageFamilyNotFoundError | ||
import unittest | ||
from rez.tests.util import TestBase, TempdirMixin, find_file_in_path, \ | ||
per_available_shell, install_dependent, program_dependent | ||
from rez.utils.platform_ import platform_ | ||
from rez.shells import create_shell | ||
from rez.packages import get_developer_package | ||
from rez.rex import RexExecutor | ||
import shutil | ||
import os.path | ||
|
||
|
@@ -200,6 +203,76 @@ def test_build_custom(self): | |
stdout = proc.communicate()[0] | ||
self.assertEqual('Oh hai!', stdout.decode("utf-8").strip()) | ||
|
||
def test_set_standard_vars_escaping(self): | ||
"""Test that set_standard_vars properly escapes environment variables.""" | ||
# Create a test package directory with special characters in description | ||
temp_pkg_dir = os.path.join(self.root, "test_special_package") | ||
os.makedirs(temp_pkg_dir) | ||
|
||
# Create a package.py file with special characters | ||
package_py_content = """ | ||
name = "test_special_chars" | ||
version = "1.0.0" | ||
description = 'A test package with "quotes" and $pecial characters & more!' | ||
authors = ["[email protected]"] | ||
requires = [] | ||
""" | ||
|
||
package_py_path = os.path.join(temp_pkg_dir, "package.py") | ||
with open(package_py_path, 'w') as f: | ||
f.write(package_py_content) | ||
|
||
# Get the developer package | ||
package = get_developer_package(temp_pkg_dir) | ||
|
||
# Get the first variant from the package | ||
variant = next(package.iter_variants()) | ||
|
||
# Create a minimal context for testing - we don't need to resolve packages | ||
# since we're only testing environment variable escaping | ||
context = self._create_context() # Empty context | ||
|
||
# Create a bash shell executor using RexExecutor | ||
bash_shell = create_shell("bash") | ||
executor = RexExecutor(interpreter=bash_shell, parent_environ={}, shebang=False) | ||
|
||
build_path = os.path.join(self.root, "build") | ||
install_path = os.path.join(self.root, "install") | ||
|
||
BuildSystem.set_standard_vars( | ||
executor=executor, | ||
context=context, | ||
variant=variant, | ||
build_type=BuildType.local, | ||
install=True, | ||
build_path=build_path, | ||
install_path=install_path | ||
) | ||
|
||
# Get the generated shell script | ||
script_output = executor.get_output() | ||
|
||
self.assertEqual( | ||
script_output, | ||
f"""export REZ_BUILD_ENV="1" | ||
export REZ_BUILD_PATH="{build_path}" | ||
export REZ_BUILD_THREAD_COUNT="{package.config.build_thread_count}" | ||
export REZ_BUILD_VARIANT_INDEX="0" | ||
export REZ_BUILD_VARIANT_REQUIRES='' | ||
export REZ_BUILD_VARIANT_SUBPATH="" | ||
export REZ_BUILD_PROJECT_VERSION='1.0.0' | ||
export REZ_BUILD_PROJECT_NAME='test_special_chars' | ||
export REZ_BUILD_PROJECT_DESCRIPTION='A test package with "quotes" and $pecial characters & more!' | ||
export REZ_BUILD_PROJECT_FILE='{package_py_path}' | ||
export REZ_BUILD_SOURCE_PATH='{temp_pkg_dir}' | ||
export REZ_BUILD_REQUIRES='' | ||
export REZ_BUILD_REQUIRES_UNVERSIONED='' | ||
export REZ_BUILD_TYPE='local' | ||
export REZ_BUILD_INSTALL="1" | ||
export REZ_BUILD_INSTALL_PATH='{install_path}' | ||
""" | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This protects against cases where a user passes something like
We were already doing that for elements in sequences anyway.