Don't allow anonymous users to upload files by poking the upload endpoint directly #182
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.
By default, it is possible for anyone, authenticated or not, to upload files to the server by poking the
markdownx_upload
endpoint directly. You can verify this by opening the admin page for any model that has aMarkdownxField
, opening the "Log out" admin link in a new tab, then dragging and dropping an image in your old tab. The file will successfully be uploaded, even though that request would have been made unauthenticated.This might be intentional, but it is surprising behaviour for someone that has added MarkdownX so that they can get a Markdown editor in their admin. I don't know if that is the majority case, but I suspect it's a common enough one that it's probably a bad idea to allow unauthenticated uploads by default - you increase your attack surface and you become a free image host to anyone that knows how to use
curl
.Instead, this PR adds a
MARKDOWNX_UPLOAD_ALLOW_ANONYMOUS
setting, which defaults toFalse
. That means that anyone who does really want to allow anonymous uploads (I could see a use case in, e.g., blog comments) can have it, but the default out-of-the-box setting is safe.Noise: The
MIDDLEWARE
noise in this PR is to make testingrequest.user
work in a unit test environment. I also removed some ancient compatibility cruft from thetests.py
while I was there.Apologies for not including the generated docs in this; if I did (possibly because of different
mkdocs
versions) it would have included far too much auto-generated noise. If I could have some hints for generating them without this noise I would be thankful :)