Reject excessively large FTP control replies#2434
Closed
somecookie wants to merge 24 commits into
Closed
Conversation
... and renamed SafeRawTokenSizeMax() to RawSizeMaxXXX(). When checking String limits in new/adjusted code X, we are trying to protect legacy code Y _that runs later/elsewhere_ and that does not check SizeMaxXXX(). We add a check to X, but it is meant for Y. We have two basic concerns about Y: * Y may concatenate our raw tokens. We can easily prevent such "pure" accumulation from exceeding the limit by checking SizeMaxXXX() in X. If accumulation were the only concern, our new code would just check SizeMaxXXX(). There would be no need for `SizeMaxXXX()+1)/3` hacks! * Y may grow/encode our raw input. We can prevent known algorithms from exceeding the limit by accounting for code Y growth factor in code X. For example, if Y concatenates raw tokens while separating them with a space character, then such an algorithm can double raw input size (at the most). If Y applies URI percent-encoding, it can triple raw input size. This is where our `SizeMaxXXX()+1)/3` hacks become handy. Since SizeMaxXXX() exceeds RawSizeMaxXXX(), checking the latter is enough. The renaming part of this change also preserves XXX in every caller that is using the formerly unnamed `SizeMaxXXX()+1)/3` hack (which had an XXX in it). We want to continue to mark such callers as problematic...
Overriding increases diff noise, touches legacy code that we want to remove, and makes it impossible to use wordlistDestroy name as an std::unique_ptr template type parameter (because there are two functions with that name), resulting in more complex and odd/asymmetric std::unique_ptr construction compared to the nearby sbufOwner construction. An acceptable alternative would be to add worldlistFree() or a similar function that does not override wordlistDestroy(). The problem stems from the unfortunate existing "safe" wordlistDestroy() API that does not use a "safe" word in its name. We cannot fix that preexisting problem without make a lot of out-of-scope changes.
This change also helps avoid using rather odd "char[]" type for the first std::unique_ptr parameter. sbufOwner now allocates and deletes "void*" memory, while `sbuf` uses a c-string "view" of that memory.
Our "token len" could incorrectly imply that we are measuring the length of a single (growing) token.
This comment was marked as resolved.
This comment was marked as resolved.
rousskov
approved these changes
Jun 4, 2026
Comment on lines
1175
to
+1176
| linelen = strcspn(s, crlf) + 1; | ||
| replyLength += linelen; |
Contributor
There was a problem hiding this comment.
I believe this "total" length calculation math protects Squid from raw input expansion due to a combination of percent-encoding and existing wordlist items concatenation code. These kind of protections are rather weak, of course, but that is why we have already added a warning for the admins about increasing reply_header_max_size and why the corresponding limit functions have XXX in their names. This old problem will go away with the last String instance.
This comment does not request any changes.
squid-anubis
pushed a commit
that referenced
this pull request
Jun 7, 2026
When parsing FTP control replies, `Ftp::Client::parseControlReply()` stores individual lines in the `ctrl.message` wordlist. The stored values are later combined, appended, encoded, and/or converted to String objects, exposing the results to `String::SizeMax_` limitations. Recent commit 46f3f80 already ensures `reply_header_max_size` limits for control replies. This change adds checks for cases where `reply_header_max_size` configuration exceeds the recommended maximum value. It also protects any sensitive worldlist-manipulating code that might become reachable before `reply_header_max_size` limit is checked. Excessively large FTP control replies now lead to ERR_FTP_FAILURE. This is a Measurement Factory project.
Collaborator
|
queued for backport to v7 |
kinkie
pushed a commit
that referenced
this pull request
Jun 7, 2026
When parsing FTP control replies, `Ftp::Client::parseControlReply()` stores individual lines in the `ctrl.message` wordlist. The stored values are later combined, appended, encoded, and/or converted to String objects, exposing the results to `String::SizeMax_` limitations. Recent commit 46f3f80 already ensures `reply_header_max_size` limits for control replies. This change adds checks for cases where `reply_header_max_size` configuration exceeds the recommended maximum value. It also protects any sensitive worldlist-manipulating code that might become reachable before `reply_header_max_size` limit is checked. Excessively large FTP control replies now lead to ERR_FTP_FAILURE. This is a Measurement Factory project. --------- Co-authored-by: Ricardo Ferreira Ribeiro <garb12@pm.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When parsing FTP control replies,
Ftp::Client::parseControlReply()stores individual lines in the
ctrl.messagewordlist. The storedvalues are later combined, appended, encoded, and/or converted to String
objects, exposing the results to
String::SizeMax_limitations. Recentcommit 46f3f80 already ensures
reply_header_max_sizelimits forcontrol replies. This change adds checks for cases where
reply_header_max_sizeconfiguration exceeds the recommended maximumvalue. It also protects any sensitive worldlist-manipulating code that
might become reachable before
reply_header_max_sizelimit is checked.Excessively large FTP control replies now lead to ERR_FTP_FAILURE.
This is a Measurement Factory project.