]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix stack buffer overflow when parsing Digest Authorization (#1517)
authorsquidadm <squidadm@users.noreply.github.com>
Tue, 17 Oct 2023 15:50:56 +0000 (04:50 +1300)
committerGitHub <noreply@github.com>
Tue, 17 Oct 2023 15:50:56 +0000 (04:50 +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".

---------

Co-authored-by: Alex Bason <nonsleepr@gmail.com>
Co-authored-by: Amos Jeffries <yadij@users.noreply.github.com>
src/auth/digest/Config.cc

index d42831a553c086aee935a674eb761c54035ee095..be9f3c433a09fb028d74a781eb0c9fe3654f3f4d 100644 (file)
@@ -844,11 +844,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, "bad nc buffer size");
+                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: