feat(nginx): Trust admins to upload large files #1662
Merged
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.
This request implements the recommendation in #1661
However, I've done some more follow-up research that leaves me uncertain on whether to recommend merging this.
What's checked first: authentication or the upload size?
In the linked issue, I recommended allowing unlimited upload size, but scoped to a route that only works for admins. That's a sound idea, but it only works to block unwanted large uploads if authentication happens before all that data is sent. So I put together a test:
I submitted an upload to admin-only endpoint as an unauthenticated user, sending a file that was larger than
client_max_body_size
. So my request has two reasons to fail: It's not authenticated and it's too big. The question is: which problem will problem trigger first?In my tests, the
client_max_body_size
limit was always triggered before the request was passed to Ghost and the app had a chance to run the authentication middleware.To try the force the request to get passed through from Ngnix to Ghost before it was fully uploaded, I tried setting these directives:
To summarize: Since Ghost is open source, it doesn't help security to scope large file uploads to a single authenticated route, because that route is known, and Ghost (apparently) can't check the authentication until the upload is complete. And since it's better to be "secure by default", perhaps the current max upload setting of 50 mb is a reasonable default. Those who need to upload videos can change the default.
Detour: Does
proxy_request_buffering
perform better on or off?As part testing this, I ended up testing uploading a 400 Mb file repeatedly, both with `proxy_request_buffering on and off. My hypothesis was that uploads would perform better with the buffering off because Ghost could start processing the first part of the file even while the last part is still uploaded.
The result was instead that it was about 7x faster to leave
proxy_request_buffering
enabled. I can't explain why. But here you can see in the Ghost logs the different valuels changes as I toggled the directive back and forth and re-tested:The conclusion there is no change is recommended to the current
proxy_request_buffering
directive either.