Security
meta-scraper parses HTML written by third parties and parseUrl() downloads whatever URL it gets. Both matter as soon as URLs or pages come from users.
Server-side request forgery (SSRF)
When a user can choose the URL (a link preview, "import from URL", a webhook preview), they can make your server request addresses they cannot reach themselves:
http://localhost:6379/,http://127.0.0.1:9200/: services on the server itself;http://10.0.0.5/admin,http://192.168.1.1/: the private network;http://169.254.169.254/latest/meta-data/: the cloud metadata service, which can hand out credentials;- a public URL that redirects to any of these.
parseUrl() does not check URLs. Before you call it with a URL from a user:
- Allow only
httpandhttps. Rejectfile:,gopher:,ftp:and everything else. - Resolve the host and reject private, loopback, link-local and reserved addresses (
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE), for IPv4 and IPv6. - Pin the connection to the address you checked (
CURLOPT_RESOLVE), so DNS cannot return a different address between your check and the request (DNS rebinding). - Check every redirect target the same way (
on_redirecton your own Guzzle client), or disable redirects ('allow_redirects' => false). - Set timeouts and limit the number of redirects.
Or send all scraping requests through an egress proxy that blocks internal networks (proxy option), which also covers what your code forgets.
The link preview example implements steps 1 to 5 in about 60 lines and shows them blocking 169.254.169.254, localhost, private addresses, IPv6 loopback, other schemes and a redirect to the metadata service. Redirect targets are checked in on_redirect but resolved again by cURL; an egress proxy closes that gap too.
Resource limits
A hostile or broken server can answer slowly or with a huge body:
- set
timeout(whole request) andconnect_timeout; the default only has a 5 second connect timeout; - limit redirects (
allow_redirectswith a smallmax); - the whole body is read into memory: to cap its size, use your own client with the
on_headersoption (reject a largeContent-Length) or aprogresscallback that aborts after N bytes; - run scraping in a queue worker, not in the web request of the user who submitted the URL.
Untrusted values
Everything in Meta comes from the page author:
- Escape titles, descriptions, names and URLs before you put them into HTML (
htmlspecialchars()or your template engine's auto-escaping). - Validate URLs such as
getOgImage()andgetOgUrl()before you link, embed or download them: allow onlyhttp/https(anog:imageofjavascript:alert(1)is a valid string), and treat them as user input when your server fetches them (SSRF again). - Do not trust
getOgUrl()as proof of where the page lives, or the author and dates as facts: any page can claim anything.
$meta = $scraper->parse('<meta property="og:title" content="<img src=x onerror=alert(1)>">', [new OgDomParser()]);
echo $meta->getOgTitle(), "\n"; // raw: never print this into HTML
echo htmlspecialchars((string) $meta->getOgTitle()), "\n"; // escaped<img src=x onerror=alert(1)>
<img src=x onerror=alert(1)>Parsing cost
The parsers work on strings in memory. OgDomParser builds a DOM of the whole document and SchemaParser runs json_decode() on every JSON-LD block; neither follows external references (no external entities, no @context downloads). Limit the body size as above if pages come from untrusted hosts.
TLS
Guzzle verifies TLS certificates by default (verify: true). Do not turn it off; for an internal CA, pass the path of its bundle as verify.
Reporting a vulnerability
Do not open a public issue. Use GitHub private vulnerability reporting or email the maintainer; the security policy has the details and the supported versions.