Skip to content

Fix arbitrary dll load via json injection - #2269

Merged
kunal-vaishnavi merged 3 commits into
mainfrom
asonawane/load
Jul 13, 2026
Merged

Fix arbitrary dll load via json injection#2269
kunal-vaishnavi merged 3 commits into
mainfrom
asonawane/load

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request enhances the security of JSON handling in src/config.cpp by introducing a robust JSON string escaping function. This prevents potential JSON injection vulnerabilities when user-supplied values are embedded in JSON documents. The most important changes are:

Security Improvements:

  • Added a new EscapeJsonString function to safely escape all necessary characters in strings before embedding them in JSON, handling quotes, backslashes, control characters, and other non-printable characters.
  • Updated the SetProviderOption function to use EscapeJsonString on provider_name, option_name, and option_value before inserting them into the JSON document, preventing malicious input from altering the JSON structure.

Dependency Updates:

  • Included the <cstdio> header to support the use of std::snprintf in the new escaping function.

Copilot AI review requested due to automatic review settings July 6, 2026 17:48
@apsonawane
apsonawane requested a review from a team as a code owner July 6, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to harden src/config.cpp against JSON injection by introducing EscapeJsonString and using it when building a JSON snippet inside SetProviderOption before parsing it with the repo’s JSON parser.

Changes:

  • Added EscapeJsonString(std::string_view) to escape caller-supplied fragments before embedding them into a JSON string literal.
  • Updated SetProviderOption to escape provider_name, option_name, and option_value before concatenating the JSON document.
  • Added <cstdio> for std::snprintf.

Comment thread src/config.cpp Outdated
The local JSON parser (src/json.cpp) throws on any \uXXXX escape, so emitting \u00XX for C0 control characters would cause SetProviderOption to produce JSON its own parser cannot consume. Reject raw control characters (other than the shortcut-escaped \b \f \n \r \t) with a clear runtime_error instead. Removes the now-unused <cstdio> include.
@apsonawane
apsonawane enabled auto-merge (squash) July 7, 2026 22:34
@kunal-vaishnavi
kunal-vaishnavi disabled auto-merge July 13, 2026 18:33
@kunal-vaishnavi
kunal-vaishnavi merged commit e4f1222 into main Jul 13, 2026
60 of 65 checks passed
@kunal-vaishnavi
kunal-vaishnavi deleted the asonawane/load branch July 13, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants