API PROTECTION

Protecting expensive API actions from automated abuse

Find the point where a request consumes money, capacity or inventory, then put a selective protection policy in front of that action.

By Blokk · Published

Follow the request to its cost

An API request can look small while starting an expensive job. Consider a service that generates a report from uploaded documents. The initial request may contain only a job reference, but accepting it commits processing time and storage. The most useful protection point is before the application commits those resources.

Map that path for one feature. Note what the caller requests, what the server verifies, what work is queued and which external services are called. OWASP’s resource-consumption guidance highlights both infrastructure use and services billed per request. Include both when deciding what the feature can safely accept.

Choose the unit you need to protect

For the report service, a request count is only part of the picture. One request might generate one short report; another might request a batch. Decide which unit best represents the work: documents processed, pages rendered, active jobs or credits spent. Give that unit a limit alongside a suitable request limit.

Make the decision visible to the product team. A paid customer’s scheduled export and an anonymous trial should not accidentally share the same entitlement. OWASP separately identifies excessive access to sensitive business flows, where harm comes from using a valid feature beyond what the business intends.

Write a small contract for the action

For an illustrative report workflow, the contract might allow an authenticated account to create reports within its plan, with a bounded number running at once. A request must refer to documents that account can access. A retry must refer to the existing job rather than start a second one. These are application rules regardless of whether the caller uses a browser or an agent.

Once those rules are clear, decide where automation evidence can improve the response. A qualifying unwanted pattern might pause new jobs for review while leaving existing reports accessible. Keep the permission check, allowance check and automation assessment distinct so an integration failure cannot silently remove the ordinary limits.

  • Protected action: accepting a new report job.
  • Permitted use: authorised documents and the account’s agreed allowance.
  • Cost boundary: before the job enters the processing queue.
  • Response scope: new jobs for the affected account, with a defined release path.

Apply the decision where work is accepted

Check that every route into the operation applies the policy. A button on the website, an API client and a scheduled integration may all reach the same job queue. Put the final decision at the shared server boundary, where the application has the account and job context it needs.

Keep concurrency in the design. Two requests arriving together should not each consume the same remaining allowance. Test the quota reservation and job creation together, including retries after a lost response. The assessment result can inform the decision; the application still owns the transaction that starts the work.

Test the client you want to keep

Prepare an approved automated client as a comparison case. Run its normal workload, a documented burst and a retry after an interrupted connection. Check the experience when its allowance is exhausted: the client should receive a useful response and an understandable route to resume.

For an HTTP rate limit, RFC 6585 defines the 429 response and an optional Retry-After header. Use the status and retry information consistently with the API contract. A temporary limit should not force a client to guess whether it needs to wait, reduce a batch or contact support.

Review work accepted, refused and completed

Track whether the protected operation actually started, whether it completed and what it consumed. Keep those records separate from policy matches. A rule match recorded after the expensive job has already started may help an investigation, but it does not show that the cost was avoided.

Blokk’s API integration lets your backend use automation assessments within this action-level policy. Start with the operation that matters most, test the response under normal and unwanted use, and review corrections as the policy runs. The result should be an API that useful clients can rely on and a business rule your team can explain.

Sources and further reading

Build the protection policy for your workflow.

Define the unwanted action, approve a supported response and test permitted use. Blokk’s approach keeps the evidence behind a rule and the exceptions, outcomes and corrections that help you oversee it. Choose your next step below.

Get started

All articles