-
Notifications
You must be signed in to change notification settings - Fork 120
Zugangsdaten in URLs im Log unkenntlich machen #3780
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
andreasmuellerka
wants to merge
1
commit into
openWB:master
Choose a base branch
from
andreasmuellerka:redact-url-credentials-in-logs
base: master
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
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,46 @@ | ||
| import pytest | ||
|
|
||
| from helpermodules.logger import redact_sensitive_info | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("message, expected", [ | ||
| pytest.param("connection to ws://openwb:secret@ocpp.example.com/v16/ established", | ||
| "connection to ws://openwb:***REDACTED***@ocpp.example.com/v16/ established", | ||
| id="websocket url"), | ||
| pytest.param("wss://openwb:secret@ocpp.example.com:443/v16/", | ||
| "wss://openwb:***REDACTED***@ocpp.example.com:443/v16/", | ||
| id="port is kept"), | ||
| pytest.param('{"url": "ws://openwb:secret@ocpp.example.com/v16/", "version": "1.6"}', | ||
| '{"url": "ws://openwb:***REDACTED***@ocpp.example.com/v16/", "version": "1.6"}', | ||
| id="url embedded in json"), | ||
| pytest.param("ws://user:p@ssword@host/", | ||
| "ws://user:***REDACTED***@host/", | ||
| id="at sign within password"), | ||
| pytest.param("ws://openwb:***REDACTED***@ocpp.example.com/v16/", | ||
| "ws://openwb:***REDACTED***@ocpp.example.com/v16/", | ||
| id="already redacted"), | ||
| ]) | ||
| def test_redact_url_credentials(message, expected): | ||
| assert redact_sensitive_info(message) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("message", [ | ||
| pytest.param("http://192.168.1.5:8080/api?value=1", id="url without credentials"), | ||
| pytest.param("https://api.example.com/mail?to=someone@example.com", id="at sign in query"), | ||
| pytest.param("http://host:8080 unreachable, contact someone@example.com", id="mail address after url"), | ||
| ]) | ||
| def test_keep_url_without_credentials(message): | ||
| assert redact_sensitive_info(message) == message | ||
|
|
||
|
|
||
| def test_redact_url_credentials_and_known_field(): | ||
| message = '{"url": "ws://openwb:secret@ocpp.example.com/v16/", "password": "abc123"}' | ||
| expected = '{"url": "ws://openwb:***REDACTED***@ocpp.example.com/v16/", "password": "***REDACTED***"}' | ||
|
|
||
| assert redact_sensitive_info(message) == expected | ||
|
|
||
|
|
||
| def test_redact_url_credentials_with_sensitive_field_as_user_name(): | ||
| # If the user name matches an entry of KNOWN_SENSITIVE_FIELDS, the field pattern applies on | ||
| # top and truncates the url. The password is removed in that case as well. | ||
| assert redact_sensitive_info("ws://token:secret@ocpp.example.com/v16/") == "ws://token=***REDACTED***" |
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.
exc_tracebackist ein Traceback-Objekt, kein formatierter Text. Die Interpolation ergibt nurTraceback:<traceback object at 0x7f...>, unabhängig davon, was die Exception enthält. Es gibt hier also nichts zu redigieren.Der Wert, der Zugangsdaten enthalten kann, ist
exc_value– der geht eine Zeile darüber durchredact_sensitive_info().Davon abgesehen ist die Zeile in ihrer jetzigen Form wenig hilfreich: In
thread_errors.loglandet eine Objektadresse statt des Stacktrace.threading_excepthookmacht es darüber mittraceback.format_tb()richtig. Das ist aber bestehendes Verhalten und nicht Gegenstand dieses PR – ich lasse es hier bewusst unverändert.