All entries

    How to Keep Third-Party API Keys Out of a React App

    Move credentials for a billable third-party API into a server function, and give the browser a narrow operation it can call.

    A laptop sends a request through a staffed kiosk with a padlock
    Conceptual pixel-art illustration.

    Move credentials for a billable third-party API into a server function, and give the browser a narrow operation it can call.

    Build the example

    An image metadata demo can accept an allowlisted asset ID and return dimensions. Let the server map the ID to a trusted upstream request and attach its credential there. Require the caller’s appropriate access, validate the request shape, cap payload and upstream response sizes, and return only the fields the browser needs. A generic proxy that accepts a URL creates an additional arbitrary-request problem.

    Give your fake upstream service one endpoint that requires a dummy credential. Record its received operation and return a harmless fixed size. Try modifying the browser request to call a different operation and verify that it is rejected before the upstream sees it. This gives you an observable boundary even without a real API account.

    Watch the failure boundary

    Authorization should answer whether this caller can run this operation for this resource, not merely whether the caller signed in. Add a quota for the operation and exercise it with two fictional accounts. Instrument response classes and duration at the proxy so you can investigate abuse without logging unredacted upstream headers or full input bodies.

    Verify the behavior

    Build the client and search its emitted assets for a harmless canary substituted for the server-only value. Then call the function with a fabricated ID, an oversized body and no session. Review errors and logs for upstream credentials. Keeping the credential off the bundle still leaves usage authorization and rate limits to enforce.

    FURTHER READING

    Sources

    Technical references checked .

    END OF ENTRY / 35
    Eeshan Singh with Big Ben in London
    BEHIND THE JOURNAL

    Eeshan Singh

    I’m Eeshan Singh Pokharia, an AI Full Stack Developer and CoFounder of UltraFit360. I work across AI features, full-stack product development, and web and mobile experiences—from Figma and frontend interactions to the systems behind them.

    Authorization should answer whether this caller can run this operation for this resource, not merely whether the caller signed in. Add a quota for the operation and exercise it with two fictional accounts. Instrument response classes and duration at the proxy so you can investigate abuse without logging unredacted upstream headers or full input bodies.

    Meet the author
    THE CONVERSATION

    Your side of the story.