Logo vun Security

Security

Organisatioun
RevenueCat
security

Use this skill when hardening a Google Play Billing integration against fraud. Covers server side receipt verification, replay attack protection, device fingerprinting, velocity checks, and the most common billing fraud patterns.

Iwwersiicht

EditeurRevenueCat
Repositoryplay-billing-skills
Skill-Nummsecurity
Stären
58
Forks
0
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzApache-2.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum RevenueCat op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Security an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/security
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RevenueCat/play-billing-skills.git /tmp/play-billing-skills
mkdir -p .claude/skills
cp -r /tmp/play-billing-skills/google-play/security .claude/skills/security
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Security an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Security automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Security net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Securing Google Play Billing

Anything running on the user device can be tampered with. If your trust model lives in the client, you have already lost. This skill shows you how to move trust to your backend and defend against the attack patterns you will actually see in production.

Phase 1: Assess

Before you write a line of defensive code, answer these questions about your current integration:

  • Where does purchase verification happen today? Client, backend, or both?
  • Does your database enforce a unique constraint on purchaseToken?
  • Do you set obfuscatedAccountId and obfuscatedProfileId on every purchase flow?
  • Do you poll the Voided Purchases API on a schedule?
  • Do any access decisions rely on System.currentTimeMillis() from the device?

Any "no" answer maps to a layer you are missing below.

Phase 2: Plan the Layered Defense

Fraud prevention is not a single check. It is a stack of controls where each layer catches a different attack class. Plan all of them, even if you ship them incrementally.

LayerPurposeWhere it runs
1. Backend receipt verificationConfirm the purchase exists in Google's recordsYour server, via purchases.products.get / purchases.subscriptionsv2.get
2. Response field validationCatch product swaps and cross app token reuseYour server (check productId and purchaseState; the package is bound by the request path)
3. Purchase state checkReject PENDING and expired purchasesYour server
4. Replay protectionBlock reuse of valid tokensUnique constraint on purchase token column; for subscriptions, once a new token is verified as purchased (not while it is SUBSCRIPTION_STATE_PENDING), revoke the entitlement on its linkedPurchaseToken
5. Token to user bindingDetect token sharing across accountsYour server (store and compare userId on duplicates)
6. AcknowledgementPrevent auto refund at 3 day markYour server, after entitlement grant
7. Voided purchase syncRevoke access on refunds and chargebacksvoidedPurchaseNotification RTDN in real time, plus a daily purchases.voidedpurchases.list backfill with type=1 (includes subscriptions; key by orderId) over the last 30 days
8. Device and profile signalsGive Google and yourself correlation dataClient sets obfuscatedAccountId / obfuscatedProfileId before launching the flow
9. Integrity and pinningRaise the cost of modified APKsPlay Integrity API plus TLS certificate pinning
10. Server time of recordDefeat timezone manipulationAll time decisions use server clock

Decide the order based on risk. For most apps: layers 1 through 6 are non negotiable for launch. Layer 7 follows within the first week. Layers 8 through 10 harden against the targeted attacks you will see later.

Phase 3: Execute

Step 1: Send the token from client to backend

Keep the client thin. Its only job is to hand the token to your server along with the current user identifier.

kotlin
override fun onPurchasesUpdated(
    result: BillingResult,
    purchases: List<Purchase>?
) {
    if (result.responseCode != BillingResponseCode.OK) return
    purchases?.forEach { p ->
        if (p.purchaseState == PurchaseState.PURCHASED) {
            api.verify(p.purchaseToken, p.products, currentUserId)
        }
    }
}

Send over HTTPS. Pin the server certificate if you can. Include your own auth token so the server knows which user is claiming the purchase.

Step 2: Verify on the backend and bind the token to the user

The server is the only place that decides whether a purchase is real. Call the Google Play Developer API, validate the response, then atomically insert the entitlement under a unique constraint on purchase_token. That constraint is your replay defense.

python
def grant_entitlement(token, claimed_product, user_id):
    # The package is bound by the request path: Google rejects a token from another app.
    record = play_api.get_purchase(PACKAGE, claimed_product, token)
    if record.get("productId", claimed_product) != claimed_product:
        raise PurchaseRejected("product mismatch")
    state = record["purchaseState"]
    if state == 2:  # PENDING (includes pre orders): not a rejection, do not refund; grant after ONE_TIME_PRODUCT_PURCHASED
        raise PurchasePending("pending")  # a separate exception from PurchaseRejected
    if state != 0:  # 1 = CANCELED
        raise PurchaseRejected("not purchased")
    existing = db.entitlements.find_by_token(token)
    if existing:
        if existing.user_id != user_id:
            security_log.flag("token_reuse", token, user_id)
        return existing
    db.entitlements.insert_unique(token, user_id, record.get("orderId"))  # promo code purchases have no orderId
    play_api.acknowledge(PACKAGE, claimed_product, token)

Two things do the real work here. First, the unique insert on token means a replayed token from any account is a database conflict, not a second grant. Second, comparing the claiming user_id against the original owner on every lookup surfaces token sharing and account abuse patterns that a naive "already processed, return success" path would hide.

If a purchase fails validation or abuse checks (for example a product mismatch; a PENDING purchase is not a failure), do not grant it and do not leave it to expire unacknowledged: call orders.refund with revoke=true for its orderId so Google records that you rejected it.

Step 3: Add device and profile signals before the purchase

Set both obfuscated identifiers on every purchase flow. They cost nothing and give Google, and you, a way to correlate across sessions and Google accounts.

kotlin
val params = BillingFlowParams.newBuilder()
    .setProductDetailsParamsList(listOf(productParams))
    .setObfuscatedAccountId(sha256(currentUser.id))
    .setObfuscatedProfileId(sha256(currentUser.activeProfileId))
    .build()
billingClient.launchBillingFlow(activity, params)

Both values come back in the purchase record, so your backend can reconcile them with your user database even if the user switches Google accounts.

Fraud Pattern to Mitigation Reference

Fraud patternPrimary mitigationBackstop
Modified APK removes client checksBackend receipt verificationPlay Integrity API, R8 obfuscation
Fabricated purchase tokenspurchases.products.get returns error, server rejectsPackage name and product ID checks
Stolen token from another appThe API call scoped to your packageName rejects foreign tokensToken to user binding
Product swap (cheap token, expensive claim)productId validation against client claimPrice recorded from API response, not client
Replayed token on same accountUnique constraint on purchase_tokenIdempotent grant returns existing record
Replayed token across accountsToken to user binding with alert on mismatchDevice fingerprint correlation
Pending payment treated as paidReject purchaseState == 2, wait for RTDNAcknowledge only after state becomes PURCHASED
Missed acknowledgement triggers auto refundServer side acknowledge after grant with retryMonitor acknowledgement failures as high priority
Refund abuse and chargebacksvoidedPurchaseNotification RTDN plus daily voidedpurchases.list?type=1 backfillGraduated enforcement (warn, restrict, ban)
Consumable refund after spendDeduct refunded amount from user balanceRestrict access until balance is non negative
Account sharing across many devicesConcurrent device limit, device fingerprintingFlag high distinct device count per token
Timezone and clock manipulationServer clock is the only clock for access decisionsSystemClock.elapsedRealtime() for offline grace
Ban evasion via new accountStore device and account identifiers of banned usersApply restrictions on first matching signal
Double entitlement after upgrade or resubscribeRevoke the linkedPurchaseToken entitlement once the new purchase is completedAlert when the linked token belongs to another user

Common Pitfalls

  • Acknowledging from the client. If the client acknowledges before your server grants entitlement, a failure leaves the user charged with no access. Acknowledge on the server, after the grant.
  • Returning 200 on duplicate tokens without checking the original owner. You miss token sharing entirely.
  • Bundling premium assets in assets/ or res/. Any APK extractor pulls them out. Host premium content on your server and gate downloads on verified entitlement.
  • Waiting for a daily batch to revoke a voided purchase. Revoke as soon as the voidedPurchaseNotification or SUBSCRIPTION_REVOKED RTDN arrives, and apply graduated enforcement (warn, restrict, ban) to the account, not delayed revocation.
  • Using System.currentTimeMillis() for trial eligibility or offer windows. The device clock is user controlled.

References

Heefeg gestallte Froen

Wat mécht de KI-Skill Security?

Use this skill when hardening a Google Play Billing integration against fraud. Covers server side receipt verification, replay attack protection, device fingerprinting, velocity checks, and the most common billing fraud patterns.

Firwat Security op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Security besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Security an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/RevenueCat/play-billing-skills/tree/main/google-play/security an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Security benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Security benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Security domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Security gratis?

Jo. De Skill gëtt vum RevenueCat ënner der Lizenz Apache-2.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇