fix(kapitalbank-uz): fix header formats and missing auth fields#1051
Draft
alex-mextner wants to merge 1 commit into
Draft
fix(kapitalbank-uz): fix header formats and missing auth fields#1051alex-mextner wants to merge 1 commit into
alex-mextner wants to merge 1 commit into
Conversation
Diagnosed by decompiling the official APK (v3.5.1) with jadx.
--- api.js ---
Header fixes (hy/p.java + yf0/a.java):
- X-App-Version: was "Android; 3.5.1-build.750release"; server expects
"3.5.1" — uses StringsKt.substringBefore(versionName, "-")
- X-Trace-Info: separator was "; ", should be " "; requestId must be a
fresh UUID per request, not a stored value
- User-Agent: bumped to okhttp/5.3.2 (matches APK)
Auth body fix (AuthRequest.java):
- /auth/by-password was missing otpSendingSource ("SMS") and
applicationId ("uz.kapitalbank.kbonline") — required by server even
though Kotlin side has defaults
assertVersionSupported() added: surfaces HTTP 426 as TemporaryError
instead of crashing on response.body access.
refreshToken() now throws TemporaryError on non-ok response instead of
asserting: console.assert doesn't throw — a 401 was silently setting all
ZenMoney state to undefined and returning normally, causing the retry
doScrape() to run with "Bearer undefined" tokens.
myIdVerifyResult() error handling: was spreading errorDetail string
({ ...string } = char indices, not properties); changed to
{ success: false, errorDetail: response.body?.errorDetail }.
--- index.js ---
- Import refreshToken; retry with refreshToken() before full re-auth
(password + SMS). Full updateToken() only triggers if refresh fails.
- isResident from XML preferences is a string ("true"/"false"); coerce
to boolean before sending to myid.uz API.
- Import TemporaryError (was missing; caused ReferenceError at runtime).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9b649f8 to
c675033
Compare
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
Users get HTTP 426 (Upgrade Required) from every API call. Error body:
{errorCode: 100015, errorDetail: "Неподдерживаемая версия приложения"}. After 426 was fixed, access token expiry triggered a re-auth loop that silently set all tokens toundefinedand crashed withresponse.body.map is not a function.Root cause
Five issues found by decompiling the official APK (v3.5.1) with jadx:
1.
X-App-Versionwrong format (hy/p.java— OkHttp client setup)The app builds this header as
StringsKt.substringBefore(versionName, "-"), giving"3.5.1"— not"Android; 3.5.1-build.750release"as the plugin was sending.2.
X-Trace-Infowrong separator and stalerequestId(yf0/a.java— header interceptor)Format is
"sessionId=<id> requestId=<uuid>"(space-separated, fresh UUID per request). The plugin used"; "separator and reused a storedrequestId.3.
/auth/by-passwordmissing required fields (AuthRequest.java)Server enforces
otpSendingSourceandapplicationIdas required fields, even though the Kotlin side has defaults. Missing fields →VALIDATION_ERROR.4.
refreshToken()usedconsole.assertinstead of throwingconsole.assertdoesn't throw in JS — on a 401 it silently set all ZenMoney state toundefinedand returned normally. The retrydoScrape()then ran withAuthorization: Bearer undefined, received another 401, and crashed withresponse.body.map is not a function.5.
myIdVerifyResult()spread a string instead of copying errorDetail{ ...response.body?.errorDetail }whenerrorDetailis a string produces{0: 'П', 1: 'р', ...}. Changed to{ success: false, errorDetail: response.body?.errorDetail }.Changes
api.js:
appVersionstrips build suffix viasplit('-')[0]→"3.5.1"generateUuid()added for per-requestrequestIdX-App-Versionsends only the semver string (no"Android; "prefix)X-Trace-Infouses space separator with a fresh UUID each callokhttp/5.3.2(matches APK)/auth/by-passwordbody includesotpSendingSource: 'SMS'andapplicationId: 'uz.kapitalbank.kbonline'assertVersionSupported()added for auth endpoints (426 → TemporaryError)refreshToken()throwsTemporaryErroron non-ok responsemyIdVerifyResult()error object fixedindex.js:
TemporaryErrorwas missing from imports (caused ReferenceError at runtime)refreshToken; retry withrefreshToken()before full re-auth. FullupdateToken()only if refresh failsisResidentcoerced to boolean (preferencesdelivers XML strings)Codex review findings
Codex flagged
X-App-Versionformat andX-Trace-Infoseparator as potential regressions. Both are false positives — the correct formats were confirmed directly from APK source (hy/p.java,yf0/a.java).