Repository navigation
Add full Mini App init data validation - #325
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #325 +/- ##
==========================================
+ Coverage 63.16% 64.89% +1.73%
==========================================
Files 40 41 +1
Lines 3404 3561 +157
==========================================
+ Hits 2150 2311 +161
+ Misses 1195 1193 -2
+ Partials 59 57 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
negasus
left a comment
There was a problem hiding this comment.
Please update webAppDataCheckString in webapp.go to sort field names first and only then format the key=value lines, as your webAppTestSignature helper already does. Sorting formatted lines gives a different order for keys such as field and field2: field2=… sorts before field=…. This does not affect the current Telegram field set, but both new validators include unknown fields in verification and could reject valid data if such fields are added.
Please add a regression case with those two keys using an independently specified expected order (field first, then field2). Telegram’s construction is documented at https://core.telegram.org/bots/webapps#validating-data-for-third-party-use. The rest of the PR looks good; go test -race ./... and go vet ./... passed on 2d7122f.
Thanks for catching this. The shared helper inherited the old validator’s whole-line sort. All three validators now sort field names before formatting the key=value lines. The order is unchanged for the fields Telegram currently documents. I added a regression fixture that explicitly puts field before field2 and verified it through all three validators. |
negasus
left a comment
There was a problem hiding this comment.
Verified the field-order fix across all three validators. The new regression test fails on the previous commit and passes on this one; go vet ./... and go test -race ./... pass.
Related: #322
Add
ValidateWebAppInitDatafor bot-token HMAC validation andValidateWebAppInitDataSignaturefor third-party Ed25519 validation. Both take the rawTelegram.WebApp.initDatastring and return the parsed data. CallCheckAuthDateseparately to enforce a maximum age.The new names use
WebApplikeAnswerWebAppQuery.ValidateWebappRequestremains supported for callers that only need the user. Both HMAC validators reject an empty token. All three validators reject separators that make signed field boundaries ambiguous.Like
InlineQuery.ChatType,WebAppInitData.ChatTypeis a string.WidgetQuery.ChatTypehas the same five documented values and usesWidgetQueryChatType. A shared named type would require callers that assign either string field to a string variable to convert it. Would you prefer that in a follow-up PR?When migrating from
r.URL.Query(), note that the new APIs report query parsing errors. For example,r.URL.Query()silently drops a pair with an unescaped semicolon.Tests cover both validation methods, malformed input, expiry, and the legacy API. Ran the suite with Go 1.27.4 and Go 1.18.10.
Telegram HMAC validation
Telegram Ed25519 validation