Repository navigation
fix(tokeer): escape JSON string values in the redeem request body - #6
Open
3304711297 wants to merge 1 commit into
Open
3304711297 wants to merge 1 commit into
3304711297 wants to merge 1 commit into
Conversation
The redeem code is taken verbatim from the bst:// URL and concatenated into a JSON request body without escaping. A value containing a double quote ends the JSON string early and changes the structure of the request, so the value can not be represented correctly. Escape the value per RFC 8259 before embedding it: double quote, backslash and the control characters (using \u00XX for the remaining ones). This is the same shape as the existing hand-rolled JSON helpers in this file.
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.
Problem
TokeerBridge::Redeem()builds the request body forPOST /drm/redeemby concatenatingthe redeem code straight into a JSON string, with no escaping:
codecomes verbatim from thebst://URL —HandleUri()splits the URL on/andpasses the remainder through unchanged:
JSON requires that
"inside a string value be escaped. A value containing a doublequote therefore terminates the string early and changes the structure of the request,
so such a value cannot be represented correctly. A backslash or a control character has
the same effect.
The scheme is registered in
HKCU\Software\Classes\bst, so the value is reachablefrom a URL handler, i.e. it is not restricted to a locally typed value.
Change
Adds a
JsonEscape()helper in the same anonymous namespace as the existinghand-rolled JSON helpers, and applies it to the value that is embedded into the
request body:
JsonEscape()escapes"and\, maps the named control escapes (\b,\f,\n,\r,\t), and emits\u00XXfor the remaining control characters, perRFC 8259.
Scope
One file, one call site. The other JSON helper in this file (
JsonString(), whichparses the response) is left as is — this change only covers the request side.
Verification
Built with MSVC 19.44 (VS 2022) in Release;
TokeerBridge.cppcompiles clean.Note for the reviewer: an unrelated pre-existing build issue in this tree surfaces
on a machine with a GBK (code page 936) system locale —
Hooks_Manifest.cppandDialog.hcontain non-ASCII characters in comments and producewarning C4819plus a syntax error atHooks_Manifest.cpp:236. It reproduces on anunmodified checkout and is not related to this change. Building with
/utf-8clearsit.