Skip to content

Address PR #180 review feedback: Complete exception sanitization coverage#181

Merged
abhimehro merged 5 commits intosentinel-log-sanitization-231878360127877934from
copilot/apply-review-comments
Feb 9, 2026
Merged

Address PR #180 review feedback: Complete exception sanitization coverage#181
abhimehro merged 5 commits intosentinel-log-sanitization-231878360127877934from
copilot/apply-review-comments

Conversation

Copy link

Copilot AI commented Feb 9, 2026

Apply PR #180 Review Feedback

Security & Code Quality Fixes

  • Fix remaining unsanitized exception logs in main.py:

    • _retry_request() - line 609: Sanitize exception in warning log
    • warm_up_cache() - line 951: Sanitize exception in warning log
    • create_folder() - line 1016: Sanitize exception in debug log
  • Improve test_exception_logging.py:

    • Add module docstring
    • Add class docstring
    • Add method docstring
    • Fix line too long on line 29 (split assertion)
    • Fix spacing: add 2 blank lines before main guard
    • Replace hardcoded "SECRET_TOKEN_123" with non-secret test value
  • Add comprehensive test coverage:

    • Test for validate_folder_url() exception redaction
    • Test for _fetch_folder_rules() exception redaction
    • Test for create_folder() exception redaction - IMPROVED
    • Test for _retry_request() exception redaction
  • Address review feedback:

    • Fixed test_create_folder_redacts_exception to create exception with sensitive token in message
    • Added strong assertions to verify both redaction and presence of [REDACTED] placeholder
    • Mocked _api_get and time.sleep to prevent test hangs
  • Validate all changes with linting and tests

    • All 5 exception logging tests pass
    • All 21 main tests pass
    • Code follows PEP 8 style guidelines
Original prompt

Hi @copilot, please open a new pull request to apply changes based on the comments in this thread. Thank you!

Custom agent used: Development Partner
The Development Partner Protocol


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@trunk-io
Copy link

trunk-io bot commented Feb 9, 2026

🚫 This pull request was requested to be canceled by Abhi Mehrotra (a GitHub user), so it was removed from the merge queue. See more details here.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

…ve tests

Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
Copilot AI changed the title [WIP] Update based on code review comments Address PR #180 review feedback: Complete exception sanitization coverage Feb 9, 2026
Copilot AI requested a review from abhimehro February 9, 2026 11:45
@abhimehro abhimehro marked this pull request as ready for review February 9, 2026 11:58
Copilot AI review requested due to automatic review settings February 9, 2026 11:58
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

👋 Development Partner is reviewing this PR. Will provide feedback shortly.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR completes exception-message sanitization in a few remaining log paths (to prevent leaking tokens/secrets into logs) and expands the exception logging test suite intended to regress those cases.

Changes:

  • Apply sanitize_for_log() to remaining exception-handling log statements in _retry_request(), warm_up_cache(), and create_folder().
  • Expand tests/test_exception_logging.py with additional scenarios meant to cover sanitization paths across URL validation, rule fetching, folder creation, and retry warnings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
main.py Ensures exceptions are sanitized before being interpolated into warning/debug logs in remaining handlers.
tests/test_exception_logging.py Adds/extends tests intended to prevent regressions in exception sanitization across multiple code paths.

Comment on lines +158 to +166
# Mock the API response to return data but cause an exception
# when trying to extract the ID
mock_response = MagicMock()
mock_response.json.return_value = {
"body": {
"groups": "invalid_format_causes_exception_with_token=ABC123"
}
}
mock_api_post.return_value = mock_response
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

test_create_folder_redacts_exception doesn't actually verify sanitization: the mocked response shape triggers an AttributeError whose message won't include the embedded "ABC123" substring, so the test can pass even if secrets are logged. Consider making the exception message itself contain a sensitive URL/query param (e.g. have response.json() raise with ?token=...) so the redaction behavior is meaningfully exercised.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +178 to +188
# Assertion - if debug was called, verify redaction
if mock_log.debug.called:
debug_calls = mock_log.debug.call_args_list

for call in debug_calls:
logged_message = str(call)
# The message should not contain raw exception data
# that might have tokens. Note: This is checking the
# general pattern. In real scenarios, the exception
# might contain URLs with tokens
pass # Debug logging happened with sanitization
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

test_create_folder_redacts_exception contains no assertions and ends with a pass, so it will succeed even if sanitization regresses. Please assert that log.debug was called and that the logged message contains [REDACTED] and does not contain the secret value.

Copilot generated this review using guidance from repository custom instructions.
abhimehro and others added 2 commits February 9, 2026 06:02
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

👋 Development Partner is reviewing this PR. Will provide feedback shortly.

1 similar comment
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

👋 Development Partner is reviewing this PR. Will provide feedback shortly.

Copy link
Owner

@abhimehro abhimehro left a comment

Choose a reason for hiding this comment

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

Hi @copilot,

Thanks for your help with this! Could you please address the following review suggestions for this pull request? Once these changes are implemented, the PR will be ready to merge.

I’ve included the specific context for the two suggestions below:


File: tests/test_exception_logging.py
Lines 158–166
test_create_folder_redacts_exception currently fails to verify sanitization because the mocked response triggers an AttributeError. Since that error message doesn't include the "ABC123" substring, the test passes even if secrets are logged. Please update the test so the exception message itself contains a sensitive URL or query parameter (e.g., by having response.json() raise an error with ?token=...) to properly exercise the redaction behavior.

File: tests/test_exception_logging.py
Lines 178–188
This test currently contains no assertions and ends with pass, meaning it will succeed even if sanitization fails. Please add assertions to verify that log.debug was called, that the logged message contains [REDACTED], and that it does not contain the actual secret value.


Thanks again!

Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

👋 Development Partner is reviewing this PR. Will provide feedback shortly.

@abhimehro abhimehro merged commit fa5152f into sentinel-log-sanitization-231878360127877934 Feb 9, 2026
8 checks passed
@abhimehro abhimehro deleted the copilot/apply-review-comments branch February 9, 2026 12:30
Copilot AI requested a review from abhimehro February 9, 2026 12:31
Copilot stopped work on behalf of abhimehro due to an error February 9, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants