Unsafe consumption of third-party APIs: treating partner data as trusted
When your service calls a partner or SaaS API, its responses are input too. How to validate them, bound redirects and timeouts, protect the credentials you hold, and plan for a partner being compromised.
Diagram
Your service as the client
Step 1 of 4
Call
Your backend calls a shipping partner.
GET https://partner.example.net/v1/rates?zip=94107
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Responses are input
- What fails
- Data from another API reaches the same sinks as user input.
- Who is affected
- Your users, if partner text is rendered or queried unsafely.
- What you would notice
- Partner fields written to the database or HTML without validation.
- What you change
- Validate partner responses with a schema and encode on output.
Redirects and timeouts
- What fails
- Following redirects or waiting forever hands control to the partner.
- Who is affected
- Your service’s availability and internal network.
- What you would notice
- HTTP clients with default redirect following and no timeout.
- What you change
- Disable redirects or allow-list targets, and set connect and read timeouts.
Credentials you hold
- What fails
- Your partner API keys are only as safe as where you store them.
- Who is affected
- Your account with the partner and its data.
- What you would notice
- Partner keys in repository config or shared across environments.
- What you change
- Keep keys in a secrets manager, one per environment, and rotate on a schedule.
Plan for a compromised partner
Ask what happens if the partner starts returning hostile data or goes slow. Circuit breakers, size limits, and a feature flag that disables the integration let you contain it without a deploy.
- Circuit breaker on error and latency
- Response size limit
- Feature flag to disable the integration
- Webhook signatures verified before processing
- Partner contact in the incident runbook
Inbound webhooks
Webhooks are third-party input arriving uninvited. Verify the signature with the shared secret, reject old timestamps, and process idempotently by event id.
expected = hmac.new(secret, f"{ts}.{raw_body}".encode(), "sha256").hexdigest()
if not hmac.compare_digest(expected, signature) or abs(time.time() - int(ts)) > 300:
abort(400)Check yourself
Recognition and the fix. Nothing here is a procedure.
A partner’s carrier name is rendered into your order page unencoded. Whose fault is the XSS?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
- 01Broken API authentication: tokens, keys, and the checks that get skippedCommon API authentication failures: unvalidated JWT claims, API keys in URLs, missing rate limits on token endpoints, and long-lived tokens.
- 02API security misconfiguration: defaults, debug modes, and permissive CORSThe configuration mistakes that turn a sound API into an exposed one: debug endpoints, verbose errors, wildcard CORS with credentials, open documentation consoles, and missing TLS settings, with a scan-and-fix workflow.
- 03Injection through API fields: JSON bodies reaching SQL, NoSQL, and shellsWhy JSON APIs are still injection targets: operator injection in MongoDB-style queries, typed fields that are never type-checked, and filter parameters passed to query builders.
- 04API inventory gaps: shadow, zombie, and undocumented endpointsYou cannot protect APIs you do not know about.
- 05GraphQL security: introspection, resolver authorization, and query costWhere GraphQL APIs go wrong — missing authorization in resolvers, unbounded nested queries, batching that defeats rate limits, and injection in resolver code — and how to review a schema and test it with a tool like InQL or graphql-cop.