]> 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)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sun, 15 Oct 2023 17:51:59 +0000 (17:51 +0000)
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 4fc3666b830362a1628f621ef8aa4925c713abb0..a3c9e938828ec2a5b24ea4782611cb73fded7d09 100644 (file)
@@ -826,11 +826,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: