-
-
Notifications
You must be signed in to change notification settings - Fork 439
Remove query parameters from logs #1997
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
bddap
wants to merge
9
commits into
tortoise:develop
Choose a base branch
from
bddap:copilot/fix-056ef898-c331-4fbb-a571-d445599ed67f
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e8b20e0
Initial plan
Copilot bbdf19b
Fix issue #1996: Remove sensitive query parameters from debug logging
Copilot e8ff19e
Add comprehensive test for query parameter logging security fix
Copilot 79606f1
Add changelog entry for security fix #1996
Copilot 9a7c34e
Fix changelog structure and format test file per review feedback
Copilot 5b9280e
Use [Unreleased] section in changelog following Keep A Changelog format
Copilot ddbcc72
Fix changelog structure: Move [Unreleased] section to top level
Copilot d679300
Merge remote-tracking branch 'upstream/develop' into copilot/fix-056e…
Copilot 814974b
use the repo's current changlog style
bddap 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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
"""Test that sensitive data is not exposed in debug logging.""" | ||
|
||
import logging | ||
from io import StringIO | ||
|
||
from tests.testmodels import User | ||
from tortoise.contrib.test import TestCase | ||
|
||
|
||
class TestLoggingSecurity(TestCase): | ||
"""Test cases for ensuring sensitive data is not logged by Tortoise ORM.""" | ||
|
||
async def test_query_parameters_not_logged_in_tortoise_db_client(self): | ||
"""Test that query parameters are not logged by tortoise.db_client logger.""" | ||
# Create a string IO to capture log output | ||
log_capture = StringIO() | ||
|
||
# Get the tortoise db_client logger and add our handler | ||
logger = logging.getLogger("tortoise.db_client") | ||
original_level = logger.level | ||
handler = logging.StreamHandler(log_capture) | ||
handler.setLevel(logging.DEBUG) | ||
formatter = logging.Formatter("%(name)s:%(levelname)s:%(message)s") | ||
handler.setFormatter(formatter) | ||
|
||
# Set up logging | ||
logger.setLevel(logging.DEBUG) | ||
logger.addHandler(handler) | ||
|
||
try: | ||
# Create a user with potentially sensitive data | ||
sensitive_email = "[email protected]" | ||
sensitive_username = "admin_with_secret_key_123" | ||
sensitive_bio = "bio with password: my_secret_password_123" | ||
|
||
user = await User.create( | ||
username=sensitive_username, mail=sensitive_email, bio=sensitive_bio | ||
) | ||
|
||
# Get the captured log output | ||
log_output = log_capture.getvalue() | ||
|
||
# Verify that the SQL query structure is still logged | ||
self.assertIn("INSERT INTO", log_output) | ||
self.assertIn("user", log_output.lower()) | ||
|
||
# Verify that sensitive data is NOT in the log output | ||
self.assertNotIn( | ||
sensitive_email, log_output, f"Sensitive email found in log output: {log_output}" | ||
) | ||
self.assertNotIn( | ||
sensitive_username, | ||
log_output, | ||
f"Sensitive username found in log output: {log_output}", | ||
) | ||
self.assertNotIn( | ||
sensitive_bio, log_output, f"Sensitive bio found in log output: {log_output}" | ||
) | ||
self.assertNotIn( | ||
"my_secret_password_123", | ||
log_output, | ||
f"Sensitive password found in log output: {log_output}", | ||
) | ||
|
||
# Test UPDATE operation | ||
log_capture.seek(0) # Reset the capture | ||
log_capture.truncate(0) | ||
|
||
new_sensitive_email = "[email protected]" | ||
user.mail = new_sensitive_email | ||
await user.save() | ||
|
||
log_output = log_capture.getvalue() | ||
self.assertNotIn( | ||
new_sensitive_email, | ||
log_output, | ||
f"Sensitive email found in UPDATE log: {log_output}", | ||
) | ||
|
||
# Test SELECT operation | ||
log_capture.seek(0) # Reset the capture | ||
log_capture.truncate(0) | ||
|
||
await User.filter(username=sensitive_username).first() | ||
|
||
log_output = log_capture.getvalue() | ||
self.assertNotIn( | ||
sensitive_username, | ||
log_output, | ||
f"Sensitive username found in SELECT log: {log_output}", | ||
) | ||
|
||
# Clean up | ||
await user.delete() | ||
|
||
finally: | ||
# Restore original logging setup | ||
logger.removeHandler(handler) | ||
logger.setLevel(original_level) | ||
handler.close() |
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
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
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
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
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.
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.
Want this too be added to an
## [Unreleased]
section? Keep A Changelog style?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.
Yes, there is already a section with unreleased version in the newer version of CHANGELOG
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.
I've added my change to that new section.
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.
814974b