VYPR
Low severity3.7GHSA Advisory· Published May 11, 2026· Updated May 13, 2026

CVE-2026-42874

CVE-2026-42874

Description

Microdot is a minimalistic Python web framework. Prior to 2.6.1, the Response.set_cookie() method does not sanitize its string arguments, and in particular will not detect the presence of the \r\n sequence in them. This can be a potential source of header injection attacks. For a header injection attack through this issue to be possible, an attacker must first infiltrate the client (for example through an independent XSS attack), so that it can send malicious information that is destined to be stored in a cookie by the server on behalf of the victim. An attacker that infiltrates one client can only orchestrate a header injection attack for that client, all other clients that were not infiltrated are safe. This vulnerability is fixed in 2.6.1.

Affected products

1

Patches

1
99b281b45fae

Sanitize cookies

https://github.com/miguelgrinberg/microdotMiguel GrinbergApr 24, 2026via ghsa
2 files changed · +10 1
  • src/microdot/microdot.py+3 1 modified
    @@ -630,6 +630,8 @@ def set_cookie(self, cookie, value, path=None, domain=None, expires=None,
                 http_cookie += '; HttpOnly'
             if partitioned:
                 http_cookie += '; Partitioned'
    +        if '\r' in http_cookie or '\n' in http_cookie:
    +            raise ValueError('invalid cookie')
             if 'Set-Cookie' in self.headers:
                 self.headers['Set-Cookie'].append(http_cookie)
             else:
    @@ -762,7 +764,7 @@ def redirect(cls, location, status_code=302):
             :param status_code: The 3xx status code to use for the redirect. The
                                 default is 302.
             """
    -        if '\x0d' in location or '\x0a' in location:
    +        if '\r' in location or '\n' in location:
                 raise ValueError('invalid redirect URL')
             return cls(status_code=status_code, headers={'Location': location})
     
    
  • tests/test_response.py+7 0 modified
    @@ -194,6 +194,13 @@ def test_cookies(self):
                            secure=True, http_only=True)
             res.delete_cookie('foo8', http_only=True)
             res.delete_cookie('foo9', path='/s')
    +        with self.assertRaises(ValueError):
    +            res.set_cookie('foo1', 'bar1\r\nSet-Cookie: foo2=bar2')
    +        with self.assertRaises(ValueError):
    +            res.set_cookie('foo1', 'bar1',
    +                           domain='example.com\r\nSet-Cookie: foo2=bar2')
    +        with self.assertRaises(ValueError):
    +            res.set_cookie('foo1', 'bar1', path='/\r\nSet-Cookie: foo2=bar2')
             self.assertEqual(res.headers, {'Set-Cookie': [
                 'foo1=bar1',
                 'foo2=bar2; Path=/; Partitioned',
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.