Repository navigation
fix(config): corrige le log d'avertissement des variables ${VAR} abse… #296
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
Merged
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """Une variable ${VAR} absente se résout en chaîne vide avec un avertissement | ||
| correctement formaté (champs structurés, pas d'argument positionnel orphelin).""" | ||
|
|
||
| import logging | ||
|
|
||
| from xcore.configurations.helper import _resolve | ||
|
|
||
|
|
||
| def test_variable_absente_donne_chaine_vide_sans_erreur_de_logging(monkeypatch): | ||
| erreurs: list[BaseException] = [] | ||
| monkeypatch.setattr(logging, "raiseExceptions", True) | ||
| monkeypatch.setattr( | ||
| logging.Handler, | ||
| "handleError", | ||
| lambda self, record: erreurs.append(record), | ||
| ) | ||
| monkeypatch.delenv("XCORE_TEST_VAR_ABSENTE", raising=False) | ||
|
|
||
| out = _resolve({"k": "${XCORE_TEST_VAR_ABSENTE}", "l": ["a-${XCORE_TEST_VAR_ABSENTE}"]}) | ||
|
|
||
| assert out == {"k": "", "l": ["a-"]} | ||
| assert erreurs == [], "le log d'avertissement ne doit pas lever d'erreur de formatage" | ||
|
|
||
|
|
||
| def test_variable_definie_est_substituee(monkeypatch): | ||
| monkeypatch.setenv("XCORE_TEST_VAR_OK", "valeur") | ||
| assert _resolve("pre-${XCORE_TEST_VAR_OK}-post") == "pre-valeur-post" |
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
Oops, something went wrong.
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.
🟡 Medium · Config can forge text log lines
When an attacker-controlled configuration contains an unresolved
${...}placeholder whose contents include a newline, and the configuration is loaded while the unescaped text formatter is active,_resolvepasses the captured variable name asvar, and_TextFormatter.formatinserts field values into text output without escaping; a newline in the name therefore forges additional log lines, misleading log consumers.Escape or remove control characters from structured field values before rendering them in the text formatter.
Prompt for AI agents