Avoid disclosing config file contents in parse error messages#2258
Closed
jiafatom wants to merge 2 commits into
Closed
Avoid disclosing config file contents in parse error messages#2258jiafatom wants to merge 2 commits into
jiafatom wants to merge 2 commits into
Conversation
When parsing genai_config.json fails, ParseConfig rethrew the raw JSON parser message, which embeds verbatim content from the file (such as JSON key names). If the config path is influenced by untrusted input, this could disclose contents of the targeted file through the error message. Keep the file path in the error so the failing file can still be identified, but no longer echo the parser's message content. Add CAPITests.ConfigParseErrorDoesNotLeakContent verifying the error names the file but does not include a key from the file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens config parsing error handling to avoid leaking genai_config.json contents through exception messages (e.g., unknown JSON key names), while still identifying which file failed to parse. This fits into the core model/config loading path in src/config.cpp and adds a C API regression test to ensure the error string does not echo config content.
Changes:
- Sanitizes
ParseConfigJSON parse failures by rethrowing a fixed error string that includes only the config file path (not the parser’s raw message). - Adds a new C API test that writes a config containing a “secret” key and asserts the thrown message mentions
genai_config.jsonbut not the key.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/config.cpp |
Replaces rethrow-on-parse-failure message to omit raw JSON parser details that could echo file contents. |
test/c_api_tests.cpp |
Adds a regression test asserting config parse errors do not leak key names from the config file. |
- Use a unique per-test temp directory (timestamp suffix) to avoid collisions/flakiness across parallel runs; drop the initial remove_all. - Do not assign the unused OgaConfig::Create result, which could trip MSVC /W4 /WX unreferenced-local-variable warnings. - Assert the error contains the "Error encountered while parsing" prefix so the test actually exercises the parse-error path rather than an unrelated file-open failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
Superseded by #2261, recreated as a non-fork branch in this repo so CI can access the internal build registry. Same commits and review fixes. |
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.
Description
When
genai_config.jsonfails to parse,ParseConfig(insrc/config.cpp) rethrew the raw JSON parser message. That message can embed verbatim content from the file being parsed — for example, a JSON key name (Unknown value "<key>"). If the config path is influenced by untrusted input, this echoes contents of the targeted file back through the error string.Change
ParseConfig, on a JSON parse failure, keep the file path in the error message (so the failing file can still be identified) but no longer append the parser's raw message content.CAPITests.ConfigParseErrorDoesNotLeakContent(no model required): writes agenai_config.jsoncontaining an unknown key, callsOgaConfig::Create, and asserts the resulting error namesgenai_config.jsonbut does not contain the key from the file.Scope / non-goals
This intentionally does not alter path handling. Accepting an arbitrary filesystem path is the intended behavior of
OgaCreateConfig/OgaCreateModel; validating which paths are permissible is the responsibility of the calling application, and adding path/..//UNC restrictions here would break legitimate use cases (relative paths, models on network shares).Testing
Built and ran the affected tests: