]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix stack buffer overflow when parsing Digest Authorization (#1517)
authorAlex Bason <nonsleepr@gmail.com>
Sun, 15 Oct 2023 13:04:47 +0000 (13:04 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Mon, 16 Oct 2023 08:58:16 +0000 (21:58 +1300)
The bug was discovered and detailed by Joshua Rogers at
https://megamansec.github.io/Squid-Security-Audit/digest-overflow.html
where it was filed as "Stack Buffer Overflow in Digest Authentication".

src/auth/digest/Config.cc

index f00e2ba6828f29a04c4e845790ad9ae700ef7ceb..3c070d2426b8ce38e2a730d0a9aaf87113236d85 100644 (file)
@@ -827,11 +827,15 @@ Auth::Digest::Config::decode(char const *proxy_auth, const HttpRequest *request,
             break;
 
         case DIGEST_NC:
-            if (value.size() != 8) {
+            if (value.size() == 8) {
+                // for historical reasons, the nc value MUST be exactly 8 bytes
+                static_assert(sizeof(digest_request->nc) == 8 + 1);
+                xstrncpy(digest_request->nc, value.rawBuf(), value.size() + 1);
+                debugs(29, 9, "Found noncecount '" << digest_request->nc << "'");
+            } else {
                 debugs(29, 9, "Invalid nc '" << value << "' in '" << temp << "'");
+                digest_request->nc[0] = 0;
             }
-            xstrncpy(digest_request->nc, value.rawBuf(), value.size() + 1);
-            debugs(29, 9, "Found noncecount '" << digest_request->nc << "'");
             break;
 
         case DIGEST_CNONCE: