RORK LABJP
MAX — Rork Max generates native Swift for every Apple platform, from iPhone to Vision ProNATIVE — It reaches native capabilities like AR/LiDAR, Metal 3D, Dynamic Island, Live Activities, and HealthKitPUBLISH — Publish to the App Store in two clicks; Rork Max is $200/monthEXPO — Standard Rork builds iOS and Android together via React Native (Expo) and is free to startPROMPT — Describe your app idea in plain English and Rork generates deployable, store-ready codePRICE — Standard Rork's paid plans start at $25/month: build with it first, then consider Max for native featuresMAX — Rork Max generates native Swift for every Apple platform, from iPhone to Vision ProNATIVE — It reaches native capabilities like AR/LiDAR, Metal 3D, Dynamic Island, Live Activities, and HealthKitPUBLISH — Publish to the App Store in two clicks; Rork Max is $200/monthEXPO — Standard Rork builds iOS and Android together via React Native (Expo) and is free to startPROMPT — Describe your app idea in plain English and Rork generates deployable, store-ready codePRICE — Standard Rork's paid plans start at $25/month: build with it first, then consider Max for native features
Articles/Dev Tools
Dev Tools/2026-06-22Advanced

Hardcoding Your OpenAI Key in a Rork (Expo) App Means It Gets Stolen — Slip a Thin Worker Proxy In Between

Embed an OpenAI or Gemini API key directly in the Expo app Rork generates and it can be extracted from the shipped binary. Here is why a key inside an app is never secret, plus a minimal Cloudflare Workers proxy that hides it (streaming passthrough included), simple abuse controls, and key rotation that needs no app review.

Rork435Expo91Cloudflare Workers19API keyssecurity5

Premium Article

The first thing you want to do when adding AI to a Rork-generated app is set EXPO_PUBLIC_OPENAI_KEY and call OpenAI straight from the app. It works. The demo is done in seconds. But that key can be pulled out by anyone who downloads your app from the App Store, in minutes.

You might assume the source is hidden because it's "compiled into the build." I assumed the same at first. In reality, a shipped app is not an encrypted treasure chest—it's a bundle of files with strings sitting in plain view. When the key leaks, the bill lands on you. Below I'll make it concrete why hardcoding is dangerous, then build—in real code—a minimal setup that slips one thin Cloudflare Workers relay in between to isolate the key on the server.

Why a key embedded in the app is never secret

The logic is simple. An app binary (an iOS .ipa, an Android .apk/.aab) is copied whole onto the user's device. The owner of that device can unpack it freely. Expo / React Native JavaScript bundles are especially readable: run them through strings or an unpacking tool and the embedded literals line up for you.

Environment variables with the EXPO_PUBLIC_ prefix are statically baked into the JavaScript bundle at build time. As the "public" in the name says, they're meant to be readable from the client. So does dropping the prefix hide it? No. Placing it in a native config file or code only raises the extraction effort slightly; the essence is unchanged.

Worse, HTTPS doesn't save you here. An attacker fully controls their own device, so they can put a man-in-the-middle proxy (such as mitmproxy) between the app and OpenAI and read their own traffic in the clear. If the request carries Authorization: Bearer sk-..., it's over.

In short, the moment it's on the client, it stops being secret. The only reliable defense for a key worth protecting is to never deliver it to the device at all.

Keys you can ship in the client vs. keys you can't

You don't need to hide every key. First, tell apart "keys designed to be used on the client" from "server-only keys." The single deciding question: if this key leaks, can a third party spend money or write data?

Key / valueClient?Reason
Firebase apiKey (config)OK to shipAn identifier, not a secret. Access control lives in Security Rules
RevenueCat public SDK keyOK to shipA public key issued for the client. Purchases are verified by server signatures
Stripe publishable key (pk_)OK to shipPublic by design. Charges are finalized by the server holding the secret key
OpenAI / Gemini / Anthropic API keyNever shipLeak it and a third party bills against your balance. Usage costs run uncapped
Stripe secret key (sk_)Never shipCan even issue refunds and transfers. Top-tier secret
Cloud admin tokensNever shipCan operate your whole infrastructure

When in doubt, ask: "if this leaks, can someone spend money or alter data?" If yes, that key cannot live on the device. This article targets that bottom-right "never ship" group—especially metered AI API keys.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A decision table that sorts keys you can ship in the client from keys you must never ship, based on design intent
A minimal Cloudflare Workers proxy that hides an OpenAI / Gemini key (with streaming passthrough) plus the Expo client code that calls it
Lightweight abuse controls so the proxy isn't open to everyone, and a rotation procedure that swaps the key without waiting on app review
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Dev Tools2026-04-13
LLM Streaming in Rork Apps: Building ChatGPT-Style Real-Time AI Responses with Expo and SSE
A complete guide to implementing LLM streaming (SSE) in React Native and Expo apps. Covers Anthropic and OpenAI streaming APIs, AbortController cancellation, error retry, Cloudflare Workers proxy, and multi-provider abstraction — with production-ready code throughout.
Dev Tools2026-06-21
Your Rork App's Photos Look Sideways Only After Upload — Normalizing EXIF Orientation and Stripping Location Metadata
A photo that looks upright in your app rotates 90 degrees once it hits your server. The cause is the EXIF Orientation tag. Here's how to bake the rotation into pixels and strip location metadata with expo-image-manipulator before uploading.
Dev Tools2026-06-21
Your Notification Opens the App but Lands on Home — Routing Rork Apps by Launch State
How to make a notification tap reliably reach its target screen. We cover the three launch states — killed, background, foreground — and a pending-route design that never drops a tap that arrives before navigation is ready.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →