API scraping
| Class | Data exposure |
|---|---|
| Also known as | Data harvesting, database scraping, OAT-011 |
| CWE | CWE-799: Improper Control of Interaction Frequency |
| OWASP API Top 10 | API4:2023 Unrestricted Resource Consumption |
| Typical severity | Medium |
| Affects | List, search and lookup routes that answer any number of requests and accept any page size |
A script calls an application's own API the way the frontend does, asking for one page of a list after another or for every possible value of a lookup, and saves each answer in a database of its own. Collecting an application's content or data like this, for use elsewhere, is API scraping.1 It works when the application does not limit how many requests one client may make, or how often.2
Description
Each request in a scraping run is one the application is built to answer. A member directory returns 20 members to anyone who asks for page 2; a contact search tells a user which of their friends have an account. The harm is in the volume. One client asks thousands of times, or asks for a page size far larger than the interface ever uses, and ends up with a copy of the whole dataset. The data may be public to visitors, or the scraper may sign in with fake or stolen accounts.1
Two limits keep the volume down: a cap on the number of records one response may contain, and rate limits on requests. An API that lacks either, or sets one badly, is open to scraping.3 Routes that return more fields of a record than the client needs make each scraped record worth more.4
Mechanism
A site at example.com shows a member directory. Its frontend calls a route that uses pagination with two parameters:
GET /api/members?page=1&limit=20
GET /api/members?page=2&limit=20
GET /api/members?page=3&limit=20A script repeats the request with the page number raised by one until a page comes back empty. If the server trusts the limit parameter, one request does the same work:
GET /api/members?page=1&limit=100000Changing the result-count parameter by hand is one way to find the weakness.3 Where a lookup route answers for any input, the scraper generates the inputs itself. To stay under per-client limits, scrapers split the work across many accounts, devices or addresses so that each one looks like an ordinary user.5
Notable incidents
On 3 April 2021 a press report described an unsecured database holding information on more than 530 million Facebook users. Meta stated that the data had been scraped from its platform before September 2019, through its contact importer, a feature that matched a user's phone contacts against Facebook accounts.6 The scrapers generated lists of phone numbers in one number format, loaded them into the contact lists of many simulated phones, and divided the uploads among those devices so that no single device crossed Meta's rate or data limits. The importer returned the matching profiles, which were collected into a separate database.5 Meta then changed the importer to stop programs that posed as its app from submitting long lists of numbers.6
Ireland's Data Protection Commission opened an inquiry on 14 April 2021 into Facebook Search and the Messenger and Instagram contact importers for the period from 25 May 2018 to September 2019. Its decision of 25 November 2022 found infringements of Article 25 of the GDPR, data protection by design and by default, and imposed fines totalling 265 million euros.7
Detection
Call each list route with a large limit, per_page or pageSize value and compare the number of records returned with the number the interface shows. Send the same request in a fast loop and note whether any response is refused with status 429. In access logs, scraping appears as one address or account walking through consecutive page numbers, or as lookups with inputs that follow a pattern, such as consecutive phone numbers.
Prevention
Cap the page size on the server
The server validates the parameter that sets how many records come back3 and holds every request to a largest page of its own:
// Express: the server decides the largest page
const MAX_PAGE = 50;
const asked = parseInt(req.query.limit, 10) || 20;
const limit = Math.min(Math.max(asked, 1), MAX_PAGE);Limit requests per client
A rate limit counts requests per address or account in a time window.3 In Express, the express-rate-limit middleware does this; past the limit it answers with status 429.8
import { rateLimit } from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
limit: 100, // requests per address per window
standardHeaders: 'draft-8',
legacyHeaders: false,
});
app.use('/api/', limiter);The built-in store keeps counts in the memory of one process; an application running on several servers needs a shared store such as Redis.8 Each route can have its own limit, stricter where the data is sensitive.3 Meta pairs its rate limits with data limits, which cap the amount of data a single person can collect through one feature.5
Return less
Each route returns only the fields its screen needs, chosen by name, instead of serialising the whole record, so the other fields never reach a scraper.4
Supabase
In Supabase, row level security decides which rows each role may read through the Data API.9 A policy that lets the anon role read a whole table makes that table readable by any script holding the public key. The Data API runs on PostgREST, whose db-max-rows setting is a hard limit on the rows one request can fetch.10 Supabase's pre-request functions can enforce rate limits, but only on POST, PUT, PATCH and DELETE requests, because reads run in read-only mode.9 Limits on reads therefore come from the policies or from a layer in front of the API.
Automation defences
Where volume itself is the harm, the defences include device fingerprinting, captchas, detection of non-human timing, and blocking of Tor exit nodes and known proxies.11
Prompt for a coding agent
Find every API route in this project that returns a list or answers a search or lookup. For each one: make the server enforce a maximum page size (50 unless the screen needs more) whatever limit, per_page or pageSize the request sends; add a rate limit per IP address and per signed-in user; and make the response include only the fields the frontend uses. If the project uses Supabase, list every row level security policy that lets the anon role read a whole table. List each file you changed and each route you were unsure about.
In SecFlash
SecFlash reports an API that answers requests without a rate limit as SF-EXP-208 on the Exposure page. On the Cloud page, SF-CLD-307 marks a Cloudflare zone with no rate limiting rule, and SF-CLD-308 marks a zone where Bot Fight Mode is off, so known scrapers pass without a challenge.
See also
- Rate limiting
- Insecure direct object reference
- Row level security
- Denial of wallet
- Personal data in logs
- Category: Data exposure
References
- a b OWASP Foundation. "OAT-011 Scraping". OWASP Automated Threats to Web Applications.
- back MITRE (2025). "CWE-799: Improper Control of Interaction Frequency". Common Weakness Enumeration, version 4.19.
- a b c d e OWASP Foundation (2023). "API4:2023 Unrestricted Resource Consumption". OWASP API Security Top 10.
- a b OWASP Foundation (2023). "API3:2023 Broken Object Property Level Authorization". OWASP API Security Top 10.
- a b c Meta (May 2021). "Scraping by the Numbers". Meta Newsroom.
- a b Meta (6 April 2021). "The Facts on News Reports About Facebook Data". Meta Newsroom.
- back Data Protection Commission (28 November 2022). "Data Protection Commission announces decision in Facebook 'Data Scraping' Inquiry". dataprotection.ie.
- a b express-rate-limit. "express-rate-limit". GitHub.
- a b Supabase (2026). "Securing your API". Supabase Docs.
- back PostgREST. "Configuration". PostgREST documentation.
- back OWASP Foundation (2023). "API6:2023 Unrestricted Access to Sensitive Business Flows". OWASP API Security Top 10.
External links
- OWASP Automated Threats to Web Applications, OWASP Foundation
- OWASP API Security Top 10 2023, OWASP Foundation