Rc Security

RevenueCat/ai-toolkit/revenuecat-play-billing/skills/rc-security

作者 RevenueCatccfc038185ec457b2ac9077f3bbf1ba947a44dbbApache-2.0; see LICENSE收录于 2026年10月9日更新于 2026年10月9日

Use this skill when hardening a RevenueCat integration on Android. Covers Trusted Entitlements response verification (INFORMATIONAL vs ENFORCED), why the server is always the authority, API key hygiene (public SDK key vs secret REST key), anonymous user identity, and purchase token protections RevenueCat provides automatically.

仅含说明Security
AI 生成的概览

审查并加固 Android 上 RevenueCat 集成的安全性,涵盖验证模式、API 密钥、用户身份与服务端权益校验。

功能
引导智能体对 RevenueCat Android 集成进行四阶段审查:发现 RevenueCat 已自动处理的事项,规划权益验证模式、权限归属位置与用户身份,给出具体配置与代码修改,并完成最终核查清单。产出包括设置 EntitlementVerificationMode、在应用中仅保留公开 SDK 密钥而将机密 REST 密钥留在服务端、为真实用户调用 Purchases.logIn,以及在服务端校验权益的建议与代码片段。此外还列出常见错误及其修复方法。
适用场景
适用于审计或加固 Android 上的 RevenueCat 集成,例如发布前或收到安全审查要求时。也适合需要检查验证模式、API 密钥存放位置、匿名用户身份或服务端权益校验的场景。
运行要求
不附带脚本,仅为说明性指令。智能体需要访问 Android 项目源码,进行服务端检查时还需后端代码。运行该技能本身不需要凭据或网络访问。

Phase 0: Intent

Tell the user: "I will review your RevenueCat security posture on Android: verification mode, API keys, user identity, and server side access decisions."

Phase 1: Discovery

Confirm what RevenueCat already covers so you can focus on the real gaps.

ConcernWho handles itHow
Receipt validation against Google PlayRevenueCat backendRuns before awaitPurchase() returns
Purchase token reuseRevenueCat backendTokens are deduplicated server side
Fabricated purchase tokensRevenueCat backendFails Google Play verification, no entitlement granted
HTTPS transport to RevenueCatSDKAlways on
Retry of token post on network failureSDKRetries on next app launch

Ask the project these questions:

  • Is EntitlementVerificationMode set? If not, CustomerInfo responses are trusted without signature checking.
  • Is the SDK configured with the public Android key (starts with goog_) or has someone accidentally pasted the secret key into the client?
  • Are real users identified with Purchases.logIn(yourUserId), or is the app still relying on anonymous $RCAnonymousID:...?
  • Do server endpoints that serve premium content verify entitlement server side, or do they trust a client sent flag?

Phase 2: Plan

Decide each of the following before changing code.

Decision A: Entitlement verification mode

ModeFailed verification does whatPick when
DISABLED (default)No signing happensOnly for quick prototypes
INFORMATIONALLogged, access still grantedYou want signal without risking false denials to real users
ENFORCEDEntitlementInfo.isActive returns falseYou accept some false negatives from proxies or VPNs in exchange for a strict client guarantee

Decision B: Where is the authority?

Even with ENFORCED, the client is not the authority for paid content. Decide whether each premium endpoint:

  1. Calls the RevenueCat REST API per request, or
  2. Reads a local has_entitlement flag driven by RevenueCat webhooks.

Option 2 is cheaper at request time, option 1 has no cache staleness. Pick one, document it, do not mix per endpoint without a reason.

Decision C: User identity

If the app is in production, plan to call Purchases.logIn("your_user_id") with your own authenticated user id. Anonymous ids are device scoped identifiers, not credentials, and are shared across users of the same device.

Phase 3: Execute

3.1 Turn on response verification

Add the mode to PurchasesConfiguration:

kotlin
PurchasesConfiguration.Builder(context, apiKey)    .entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)    .build()

Read the verification result when you inspect entitlements:

kotlin
when (customerInfo.entitlements.verification) {    VerificationResult.VERIFIED -> { /* response is authentic */ }    VerificationResult.FAILED -> { /* possible tampering, log and alert */ }    VerificationResult.NOT_REQUESTED -> { /* verification disabled */ }    VerificationResult.VERIFIED_ON_DEVICE -> { /* verified locally */ }}

Upgrade to ENFORCED once you have telemetry confirming FAILED is rare on real traffic:

kotlin
.entitlementVerificationMode(EntitlementVerificationMode.ENFORCED)

In ENFORCED, a failed signature flips isActive to false on the affected entitlement.

3.2 Keep API keys in the right place

KeyWhere it livesWhat it can do
Public Android SDK key (goog_...)Embedded in the app binaryRead and purchase for the calling user only
Secret REST API keyYour server, secret manager or env varFull REST API, admin operations, grant entitlements

In Android code, only the public key appears:

kotlin
Purchases.configure(    PurchasesConfiguration.Builder(context, "goog_PUBLIC_android_sdk_key").build())

Never commit the secret key to the app repo. Grep the Android source tree for the secret key prefix and confirm zero hits before release.

3.3 Identify real users

Call logIn as soon as you have an authenticated user id:

kotlin
val result = Purchases.sharedInstance.awaitLogIn("your_user_id")val customerInfo = result.customerInfo

Do not rely on the anonymous id as a credential. It is a device scoped identifier and does not protect purchase history on shared devices.

3.4 Enforce on the server, not on the client

Even with ENFORCED mode, every server endpoint that serves paid content checks entitlement server side:

python
def get_premium_content(user_id):    info = revenuecat.get_subscriber(user_id)    if not info.entitlements["pro"].is_active:        raise Forbidden()    return content

Or read a local has_pro flag driven by RevenueCat webhooks and check that flag per request.

Phase 4: Verify

  • Android source contains only the public SDK key. Secret key grep is clean.
  • EntitlementVerificationMode is set (not DISABLED) and telemetry for VerificationResult.FAILED is watched.
  • Real users are identified through Purchases.logIn. Anonymous ids are only used for pre login flows.
  • Every paid content endpoint on your server verifies entitlement through the REST API or a webhook driven flag. None trust a client header.

Common mistakes

MistakeWhy it hurtsFix
Shipping the secret key in the appAn attacker who decompiles the APK can call admin REST endpointsPublic key in app, secret key only on server
Leaving mode at DISABLED in productionA man in the middle can forge CustomerInfo responsesSet INFORMATIONAL or ENFORCED
Treating the anonymous id as a credentialIt is not secret and is shared across users of the same deviceCall logIn with your authenticated user id
Trusting customerInfo from the client on the serverA tampered client can claim any entitlementVerify on the server via REST API or webhook driven DB

References

来源与署名

来源:RevenueCat/ai-toolkit位于revenuecat-play-billing/skills/rc-security提交ccfc038

许可证: Apache-2.0; see LICENSE

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架