-
Notifications
You must be signed in to change notification settings - Fork 388
Disallow logging.conf from elsewhere than the app folder #825
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
Ickerday
wants to merge
3
commits into
develop
Choose a base branch
from
maintenance/disallow-logging-configs-from-outside-app-folder
base: develop
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.
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -137,6 +137,39 @@ def test_logging_configuration(self): | |
| f"Expected ValueError, but logging_configuration={command.logging_configuration}" | ||
| ) | ||
|
|
||
| inside_app_root_logging_configuration = os.path.join( | ||
| environment.app_root, "default", "logging.conf" | ||
| ) | ||
| command.logging_configuration = inside_app_root_logging_configuration | ||
| assert command.logging_configuration == inside_app_root_logging_configuration, ( | ||
| "logging_configuration should accept an absolute path inside the app directory" | ||
| ) | ||
|
|
||
| try: | ||
| command.logging_configuration = os.path.realpath(__file__) | ||
| except ValueError: | ||
| pass | ||
| except BaseException as e: | ||
| pytest.fail( | ||
| f"Expected ValueError for a path outside the app directory, but {type(e)} was raised" | ||
| ) | ||
| else: | ||
| pytest.fail( | ||
| f"Expected ValueError for a path outside the app directory, but {command.logging_configuration=}" | ||
| ) | ||
|
|
||
| # logging_configuration raises a value error when a relative path traverses outside the app directory (RCE guard) | ||
| try: | ||
| command.logging_configuration = os.path.join("..", "..", "..", "__init__.py") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add an additional test with an absolute path, one that points to an app dir (success), and the other one that points to a different place (failure). |
||
| except ValueError: | ||
| pass | ||
| except BaseException as e: | ||
| pytest.fail(f"Expected ValueError, but {type(e)} was raised") | ||
| else: | ||
| pytest.fail( | ||
| f"Expected ValueError, but logging_configuration={command.logging_configuration}" | ||
| ) | ||
|
|
||
| def test_logging_level(self): | ||
| rebase_environment("app_without_logging_configuration") | ||
| command = StubbedSearchCommand() | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright © 2011-2026 Splunk, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"): you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| from splunklib.searchcommands.environment import ( | ||
| _find_app_root, # pyright: ignore[reportPrivateUsage] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("app_file_parts", "expected_app_root_parts"), | ||
| [ | ||
| (("apps", "my_app", "bin", "command.py"), ("apps", "my_app")), | ||
| (("apps", "my_app", "bin", "linux_x86_64", "command.py"), ("apps", "my_app")), | ||
| (("apps", "my_app", "bin", "foo", "bar", "command.py"), ("apps", "my_app")), | ||
| (("some", "other", "layout", "command.py"), ("some", "other")), | ||
| ], | ||
| ) | ||
| def test_find_app_root( | ||
| app_file_parts: tuple[str, ...], expected_app_root_parts: tuple[str, ...] | ||
| ) -> None: | ||
| app_file = os.path.join(*app_file_parts) | ||
| assert _find_app_root(app_file) == os.path.abspath(os.path.join(*expected_app_root_parts)) |
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.
If
filenameis relative here, what will happen? Doesrealpathalways return the absolute path?Docs does not seem to say anything about that:
It only follows symbolic links.
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.
Seems like it does: https://github.com/python/cpython/blob/v3.13.13/Lib/posixpath.py#L388-L424