-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #3856 - Different behaviour with maxFormContentSize=0 if Content-Length header is present/missing. #3899
Fixes #3856 - Different behaviour with maxFormContentSize=0 if Content-Length header is present/missing. #3899
Conversation
…t-Length header is present/missing. Fixed zero checks and exception messages. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
…t-Length header is present/missing. Changes after review. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain in this PR what the actual fix is? I can see lots of code cleanup, but it is not apparent which part actually is the fix - specially as I can see no http2 specific code? So a description in this PR (that end up in squashed commit) would be much appreciated.
jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Outdated
Show resolved
Hide resolved
0 means a value of zero. simone tried to fix that here, but the use of -1 to mean unset / undefined makes things difficult for the cascade of values per request found in the Request.extractFormParameters method. making ContextHandler.getMaxFormKeys and ContextHandler.getMaxFormSize return sane values on JMX was also part of this effort. If the Request.extractFormParameters didn't have to interrogate the Server every time for possible max value changes this PR would be simpler (just do the calculation of max keys and max form size on ContextHandler.doStart() only). But that has the potential to break backward compatibility. |
@joakime I still don't understand exactly what it the bug and what is the fix. I see lots of code fiddling with how we handle 0 and -1, but it is not clear to me what this PR is actually doing. Note that we often use -1 to indicate "set a default value from heuristics" , which I think is what Simone is doing here. I think we also sometimes use 0 to mean unlimited elsewhere So if 0 means 0, is the intention to use max-value to mean no limit? That is a behaviour change. Anyway, if somebody can actually explain what the bug/fix is, then we can talk about what the cleanup should be. |
@gregw this issue was not about HTTP/2 - the OP was mistaken about that. As such, the fixes are primarily Another problem was the meaning of The current solution is We may break people that specified JMX is still "broken" in that the getter will show So basically this issue was all about a bad pattern for initializing those properties, using |
So why can't we just change to consistently interpreting 0 as unlimited (with or without content-length) and thus keep the behaviour ? I also think that it would be a reasonable change to always set the values in the ContextHandler (from server defaults) in doStart. Sure that means that we can't dynamically change them by changing server values on the fly, but we can change them dynamically on the context, so I think that is OK |
So if I want to set maxKeys and maxFormSize to 0 (meaning no forms) what do I do? |
@joakime I guess that if we had our time over, then making 0 mean 0 would have been the way to do that. But we didn't and 0 meant unlimited, so I don't see how we can change that in anything less than a major release like 10.0.0 ... OR Currently each context as constructed looks for: private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys", -1).intValue();
private int _maxFormContentSize = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormContentSize", -1).intValue(); These values can then be mutated with setters. If by the time a request is processed and they are still -1, then we look in server attributes: _channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
_channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys"); only if these are not found do we use default values. So currently VERY few users would ever actually set a -1 value and it is mostly used as an internal not-set flag. If users want to dynamically change, they will mostly like via the context setters and not the server attributes. So I think that it is a low risk change to set the values during construction with: private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys", 1000).intValue();
private boolean _maxFormKeysSet;
private int _maxFormContentSize = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormContentSize", 200000).intValue();
private boolean _maxFormContentSizeSet; Note the booleans that we will set true if anybody calls the setters. Then during HOWEVER - ideally these could be set via HttpConfiguration, so you could potentially have different sizes for different connectors.... hmmm is that overkill? But even if it is, we could still achieve that without using the -1. As each request is handled, we could ask the context if the value was set or not. If it is not set, we would look for a default value in the HttpConfiguration. Hmm getting complex, but possible tl;dr; changing to 0 means 0 within the current setup is not good. But if more substantial change was made to the configuration that allowed the -1 to be re-purposed to mean no limit , then I could accept a change to 0 means 0 now. |
…t-Length header is present/missing. Updated code to reflect reviews. Now lookup of system properties and server attributes is done in ContextHandler.doStart(), so that the getter always return the actual value (and this is good for JMX too). Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@gregw @joakime I have updated the code to be "correct". The previous behavior for The previous behavior for Now the behavior is identical for the 2 parameters and it is:
So we are potentially breaking people that meant |
…t-Length header is present/missing. Changed the logic to lookup server attributes if there is no context. This fixes a failing test that was explicitly setting the server attributes after start. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@WalkerWatch - This tidbit will be useful to mention in the jetty-announce mails. @sbordet so is the ContextHandler now the official truth of those settings? |
@joakime yes now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
maxFormKeys = Integer.parseInt((String)obj); | ||
} | ||
maxFormContentSize = lookupServerAttribute(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY, maxFormContentSize); | ||
maxFormKeys = lookupServerAttribute(ContextHandler.MAX_FORM_KEYS_KEY, maxFormKeys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this code... very obvious what it is doing.
Integer value = Integer.getInteger(key); | ||
if (value == null) | ||
{ | ||
Object attribute = getServer().getAttribute(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated code.... but not a big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually dead code now, I removed it.
…t-Length header is present/missing. Removed duplicated, unused, code. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
} | ||
|
||
if (maxFormContentSize < 0) | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is incompatible as seen in jenkinsci/winstone@8a8a146.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened Issue #4638
#3856.
Fixed zero checks and exception messages.
Signed-off-by: Simone Bordet simone.bordet@gmail.com