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.
Sources
Technical references checked .



