VAITP Dataset

← Back to the dataset

CVE-2021-41125

Scrapy exposes HTTP authentication credentials in requests

  • CVSS 6.5
  • CWE-522
  • Authentication, Authorization, and Session Management
  • Remote

Scrapy is a high-level web crawling and scraping framework for Python. If you use `HttpAuthMiddleware` (i.e. the `http_user` and `http_pass` spider attributes) for HTTP authentication, all requests will expose your credentials to the request target. This includes requests generated by Scrapy components, such as `robots.txt` requests sent by Scrapy when the `ROBOTSTXT_OBEY` setting is set to `True`, or as requests reached through redirects. Upgrade to Scrapy 2.5.1 and use the new `http_auth_domain` spider attribute to control which domains are allowed to receive the configured HTTP authentication credentials. If you are using Scrapy 1.8 or a lower version, and upgrading to Scrapy 2.5.1 is not an option, you may upgrade to Scrapy 1.8.1 instead. If you cannot upgrade, set your HTTP authentication credentials on a per-request basis, using for example the `w3lib.http.basic_auth_header` function to convert your credentials into a value that you can assign to the `Authorization` header of your request, instead of defining your credentials globally using `HttpAuthMiddleware`.

CVSS base score
6.5
Published
2021-10-06
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Authentication, Authorization, and Session Management
Subcategory
Insecure Authentication Mechanisms
Accessibility scope
Remote
Impact
Information Disclosure
Fixed by upgrading
Yes

Solution

Upgrade to Scrapy 2.5.1 and use http_auth_domain attribute to control credentials exposure.

Vulnerable code sample

import scrapy

class MySpider(scrapy.Spider):
    name = 'my_spider'
    http_user = 'your_username'
    http_pass = 'your_password'

    def start_requests(self):
        urls = [
            'http://example.com',
            'http://anotherdomain.com'
        ]
        for url in urls:
            yield scrapy.Request(url)

Patched code sample

import scrapy
from w3lib.http import basic_auth_header

class MySpider(scrapy.Spider):
    name = 'my_spider'
    http_user = 'your_username'
    http_pass = 'your_password'
    http_auth_domain = ['example.com']

    def start_requests(self):
        urls = [
            'http://example.com',
            'http://anotherdomain.com'
        ]
        for url in urls:
            if self.is_auth_domain(url):
                yield scrapy.Request(url, headers={'Authorization': basic_auth_header(self.http_user, self.http_pass)})
            else:
                yield scrapy.Request(url)

    def is_auth_domain(self, url):
        return any(domain in url for domain in self.http_auth_domain)

Cite this entry

@misc{vaitp:cve202141125,
  title        = {{Scrapy exposes HTTP authentication credentials in requests}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-41125},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-41125/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::