Skip to content
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

Temporarily disable form memory limit checking for files and images. #1729

Merged
merged 2 commits into from
Nov 4, 2023

Conversation

mauritsvanrees
Copy link
Member

This fixes a regression due to a low Zope form memory limit of 1MB used since Plone 6.0.7. You can use dos_protection settings in etc/zope.conf to change the limit. See plone/Products.CMFPlone#3848 and zopefoundation/Zope#1142.

Copy link

netlify bot commented Nov 2, 2023

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit e1bcbee
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/65439cf4d45d4c00089b2c00

@mister-roboto

This comment was marked as resolved.

This fixes a regression due to a low Zope form memory limit of 1MB used since Plone 6.0.7.
You can use ``dos_protection`` settings in ``etc/zope.conf`` to change the limit.
See plone/Products.CMFPlone#3848 and zopefoundation/Zope#1142.
@mauritsvanrees
Copy link
Member Author

@jenkins-plone-org please run jobs

…es and images.

This seems a better way, then increasing the limit to 16MB.
See zopefoundation/Zope#1180 (comment)
@mauritsvanrees
Copy link
Member Author

@jenkins-plone-org please run jobs

@mauritsvanrees mauritsvanrees changed the title Allow uploads up to 16 MB. Temporarily disable form memory limit checking for files and images. Nov 2, 2023
Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauritsvanrees Thanks for continuing to follow up on this.

I'm okay with this as is, but am also making a comment with a suggestion that may avoid the need for a monkeypatch.

_limit = getattr(ZopeFieldStorage, _attr, None)
if _limit:
setattr(ZopeFieldStorage, _attr, None)
logger.info(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(
logger.debug(

I don't feel strongly about this, but it feels like it's probably noise for most people.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about this either, but I think it would be good to have this noticeable, because it may remind us developers that we still need to fix this instead of having this temporary patch.

@@ -4,6 +4,9 @@


def json_body(request):
# TODO We should not read the complete request BODY in memory.
# Once we have fixed this, we can remove the temporary patches.py.
# See there for background information.
try:
data = json.loads(request.get("BODY") or "{}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://github.com/zopefoundation/Zope/blob/master/src/ZPublisher/HTTPRequest.py#L1061, I think we could do (untested):

body = request.get("BODYFILE")
data = {} if body is None else json.load(body)

This will not actually avoid reading the file into memory (https://pythonspeed.com/articles/json-memory-streaming/ makes it clear that json.load still does that) but would bypass the descriptor that enforces the VALUE_LIMIT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought BODYFILE would only be defined when an actual file is being uploaded, and not for example when you POST a login and password. But that is not true.

It does not sound like a permanent solution, as this would still offer a way to potentially DOS the server. But maybe very large uploads would still get stopped by one of the other limits. And initial testing seems to work out.

Let me open a different PR, so we still have the current one in case there are problems.

@tisto tisto merged commit 9f399ac into main Nov 4, 2023
26 checks passed
@tisto tisto deleted the maurits-patch-zope-form-memory-limit branch November 4, 2023 06:13
instification added a commit to pretagov/plone.restapi that referenced this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants