Remove login details before logging stream source#45398
Remove login details before logging stream source#45398emontnemery merged 6 commits intohome-assistant:devfrom
Conversation
Kane610
left a comment
There was a problem hiding this comment.
Would this benefit a global pre-compiled regexp rather than specifying it multiple times?
|
maybe we can also use the log filter? |
a49b9f1 to
ca8f0d1
Compare
Sure, let me do that. I'll look at the log filter too |
|
@pvizeli Not sure how the usage of the log filter is supposed to work. It looks like we need to parse out the sensitive data and then create a |
| self._thread.start() | ||
| _LOGGER.info("Started stream: %s", self.source) | ||
| _LOGGER.info( | ||
| "Started stream: %s", STREAM_SOURCE_RE.sub("//", str(self.source)) |
There was a problem hiding this comment.
Do we want to show that information has been redacted?
There was a problem hiding this comment.
We could do that, but I don't think that the fact that it is redacted has any importance. Having the username + password or maybe just the username would add more information, but aside from that just having the rest of the url is enough to identify the camera which is probably the point of the log message.
|
There are also some cheap cams which don't use standard authentication and instead embed the login details in the url. We can't predict all of these formats so we would still let these through. See the format of the RTSP url here: https://ipcamtalk.com/threads/review-top-201-super-mini-720p-hd-ip-cam-the-cheapest-ip-cam-so-far.1775/post-20322 |
634cf1a to
0b9554d
Compare
emontnemery
left a comment
There was a problem hiding this comment.
Looks pretty good overall.
The stream URL is also printed in homeassistant/components/stream/worker.py, should those also be filtered?
Please update or add tests in tests/components/stream to check that what's printed to the log is as expected, maybe something like this:
await async_setup_component(hass, "stream", {"stream": {}})
stream = create_stream(hass, "https://abcd:efgh@foo.bar")
with patch.object(hass.config, "is_allowed_path", return_value=True):
await stream.async_record("/example/path")
assert "https://abcd:efgh@foo.bar" not in caplog.text
assert "https://foo.bar" in caplog.text
Thanks, I just applied the same regex redaction to the worker message and added tests. |
f337603 to
900308a
Compare
Co-authored-by: Erik Montnemery <erik@montnemery.com>
|
Thanks, @uvjustin 👍 |
Proposed change
The stream logger currently outputs the entire stream source url which may include camera login details. While login details in the log might be useful for some, it seems like more users would prefer these details to be excluded. This PR uses a simple regex replacement to remove the login details from the url before logging.
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: