Repository navigation
Highlights
- Security fix (CWE-918, SSRF):
Article.parse()fetches images by default, and it took image URLs straight from the page (<img src>,og:image). The only validation was a URL scheme check. A page an attacker controls or influences could therefore make the server request internal addresses such as127.0.0.1, private ranges, or cloud metadata endpoints like169.254.169.254. Versions up to and including 0.9.6 are affected. - Outbound requests are now checked: every request made through
do_requestis rejected withPrivateHostErrorunless the host resolves to a public IP. Redirect targets are checked at every hop, so a public URL can't bounce to an internal host. This coversread_more_linktargets, meta-refresh targets, andSourcecategory, feed and article URLs. - Image fetching: image downloads, which don't go through
do_request, have their own check and follow redirects by hand with a check on each hop. - New option
allow_private_hosts(defaultFalse): set it toTrueto fetch private or internal hosts again. - NLP requires
nltk >=3.10: the Punkt tokenizer in nltk 3.10 splits sentences after closing quotes, which changes the generated summaries.
Breaking changes
- Requests to
localhost, private IP ranges, or internal hostnames now fail unlessallow_private_hosts=True. This includes article URLs you pass in yourself. - The
nlpextra now needsnltk >=3.10. Summaries can differ from earlier versions because of the sentence-splitting change. - nltk 3.10 rejects an
nltk_datadirectory that is writable by another account. PointNLTK_DATAat a directory you own if you hit aLookupErrorforpunkt_tab.
Upgrade advice
Anyone using newspaper4k to parse pages from untrusted or user-supplied sources should upgrade. If you must stay on an older version, set fetch_images=False to disable image fetching and validate user-supplied URLs yourself.
Known limitations
DNS rebinding between the host check and the connection is not prevented. For hard guarantees, also restrict outbound traffic at the network level.
What's Changed
- Block SSRF in image extraction, meta refresh,
read_more_linkandSourceURL handling, withallow_private_hoststo opt out - Add
PrivateHostErrorandnetwork.is_public_url() - Update NLP test fixtures for nltk 3.10 Punkt and require
nltk >=3.10
Full Changelog: 0.9.6...0.9.7