Repository navigation
Potential fix for code scanning alert no. 6: Log Injection - #16
Merged
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Torma Kristóf <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The log-injection protection lacks regression coverage verifying that warnings strip carriage returns and newlines while the original key is passed to cache.get.
1 open issue
What changed in this PR
This PR addresses log injection in the catalog cache service by sanitizing cache keys before logging Redis read failures, while preserving the original keys for cache operations.
Changes:
- Add
_sanitize_for_logto convert values to strings and remove carriage returns and newlines. - Apply sanitization to the key in
read_public_cachewarning messages.
| File | Description |
|---|---|
src/catalog/services/cache.py |
Add a sanitization helper and use it when logging failed cache reads. |
Review effort: Balanced
| return cache.get(key) | ||
| except (RedisConnectionError, RedisTimeoutError) as error: | ||
| logger.warning("catalog_cache_read_failed key=%s error=%s", key, error) | ||
| logger.warning("catalog_cache_read_failed key=%s error=%s", _sanitize_for_log(key), error) |
Contributor
There was a problem hiding this comment.
Added the regression test in commit 668a645. It verifies that a key containing both CR and LF is passed unchanged to cache.get while the formatted warning contains neither character.
Co-authored-by: tormachris <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Potential fix for https://github.com/Ctrl-Alt-GG/streams/security/code-scanning/6
General fix: sanitize untrusted values before logging by removing line-break/control characters (at least
\rand\n) so attacker input cannot split or forge log entries.Best targeted fix here: in
src/catalog/services/cache.py, sanitizekeyat the log site inread_public_cache. Add a small helper (e.g.,_sanitize_for_log) that converts input to string and strips\r/\n, then use it when loggingkey. This preserves existing behavior (same key used for cache operations) while making logging safe.Changes needed:
src/catalog/services/cache.py_now():object, returnsstr.\rand\nwith empty string.logger.warning(...)inread_public_cacheto log sanitized key.No new imports or external dependencies are required.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.