Merge lp://staging/~widelands-dev/widelands-website/pybb_attachments into lp://staging/widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 549
Proposed branch: lp://staging/~widelands-dev/widelands-website/pybb_attachments
Merge into: lp://staging/widelands-website
Diff against target: 947 lines (+425/-111)
16 files modified
mainpage/settings.py (+46/-5)
mainpage/validators.py (+30/-0)
pip_requirements.txt (+1/-0)
pybb/admin.py (+9/-2)
pybb/forms.py (+20/-13)
pybb/models.py (+14/-11)
pybb/settings.py (+1/-0)
pybb/static/css/forum.css (+4/-1)
pybb/templates/pybb/base.html (+1/-1)
pybb/templates/pybb/delete_post.html (+7/-2)
pybb/templates/pybb/inlines/attachment.html (+11/-0)
pybb/templates/pybb/inlines/post.html (+5/-9)
pybb/templates/pybb/post_form.html (+39/-1)
pybb/util.py (+149/-1)
pybb/views.py (+46/-27)
wlmaps/forms.py (+42/-38)
To merge this branch: bzr merge lp://staging/~widelands-dev/widelands-website/pybb_attachments
Reviewer Review Type Date Requested Status
GunChleoc Approve
kaputtnik (community) Needs Resubmitting
Review via email: mp+370342@code.staging.launchpad.net

Commit message

Allow attachments in the forum

Description of the change

Made attachments python3 compatible: https://bazaar.launchpad.net/~widelands-dev/widelands-website/pybb_attachments/revision/545

Set allowed file size to 5 Mb (as we have for nginx)

Delete attachment when deleting a post: https://bazaar.launchpad.net/~widelands-dev/widelands-website/pybb_attachments/revision/548

Added template for showing attachments.

Style tweaks, example: https://bugs.launchpad.net/widelands-website/+bug/964452/+attachment/5277903/+files/attachments_1.png

Autoreload css for the users if this got merged, so the users don't have to hit CTRL+F5

I'll do some explanations in the wiki and announce this change. Probably with the option to remove it again if we get too many problematic attachments.

To post a comment you must log in.
552. By kaputtnik

removed wrong div tag

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM. Do we have a restriction on file types? We won't want people to upload malicious JavaScript ans stuff lie that, so we should have a list of legal file extensions at least.

Revision history for this message
kaputtnik (franku) wrote :

Currently there is no restriction on file types. The problem is that a file may not contain what the extension says it should be. Everyone can rename 'image.js' into 'image.png'...

A list of allowed extension do not suffer. I'll try to implement some checks for validating a files type and probably an 'allowed extension list'.

What about restricting uploads to users who have written x posts prior? From my side this can be implemented.

Revision history for this message
GunChleoc (gunchleoc) wrote :

> Everyone can rename 'image.js' into 'image.png'...

That's true. It would still be an advantage though if the browser then doesn't execute it.

Doing a full validation too is definitely a better idea.

> What about restricting uploads to users who have written x posts prior?

Also a good idea

553. By kaputtnik

make attachments only available to users who had written MAX_HIDDEN_POST

554. By kaputtnik

added first file validation logic; render the post_form manually; give textarea more height

555. By kaputtnik

some reafctoring

556. By kaputtnik

added check for .wgf (widelands savegames); added more comments

557. By kaputtnik

merged trunk

558. By kaputtnik

use Image verify()

Revision history for this message
kaputtnik (franku) wrote :

I am a bit lost here...

Some checks are made now, but i am unsure if we need them all. What is implemented:

1. Link of Attachment:
If a user clicks on a link of an attachment, he will be ever prompted for a download (or to open the file with an associated program), even if it is a file which the browser may can display, e.g. an image (png, jpg) or text file. This is not optimal, but i think it is more secure.

2. Restricting upload permission
A user has only permission to upload files, if he has had written 5 posts prior. The number of 5 derives from MAX_HIDDEN_POST at the moment, but i think it's better to have an own value for this. What number do we want?

3. Allowed extensions:
Added a list:
ALLOWED_EXTENSIONS = ['wgf', 'jpg', 'jpeg', 'gif', 'png', 'ogg', 'lua', 'ods', 'zip', 'json', 'txt', 'csv']
I am unsure if this list will be ever complete. E.g. some may want to upload some other types of files (e.g. py, odg, doc, ...)

4. Extension handling:
- Files without extension aren't allowed (can be problematic e.g. with the campvis file)
- For 'wgf' files: Check if some base entries can be found (e.g. '/binary/' or '/minimap.png')
- For image files: Check if this is really an image using the Pillow library. This finds corrupted .png but not corrupted .jpg
Do we need a check for each allowed extension?

5. Comparing Mime-Types:
When uploading a file, a Mime-Type (content-type) is also submitted. The submitted mime-type is mostly derived from the extension of the file. E.g. if you rename a file from 'image.png' to 'image.txt' the OS (or browser) sends the Mime-type 'text/plain', which is obviously wrong. To prevent such mime-type mismatch, a check is made which compares the sent mime-type with the mime-type derived from python-magic. e.g. python magic will show for 'image.txt' the mime-type 'image/png'.

As said, i am a bit lost, not really knowing if we need all this checks, or if they are enough at all :-S Any opinions?

Revision history for this message
GunChleoc (gunchleoc) wrote :

2. I have no opinion on this at this time. Maybe 10 or 20? We can easily change the value if it becomes a problem.

> Files without extension aren't allowed (can be problematic e.g. with the campvis file)

campvis will be replaced by campaigns.conf for the next version, so don't worry about it - we can allow .conf

Other extensions that we're using for Widelands & that might be interesting:

.wai - AI
.wmf - Map
.wrpl - Replay - useless with the accompanying .wgf though.

> Do we need a check for each allowed extension?

Since attachments are marked for download anyway, I'd say that checking for those that are easily checked will do for now.

Revision history for this message
kaputtnik (franku) wrote :

> Other extensions that we're using for Widelands & that might be interesting:

> .wai - AI
Ok

> .wmf - Map

I forgot to mention: If the extension is wmf, an errormessage is shown: "This seems to be a widelands map file. Please upload it at our maps section."

> .wrpl - Replay - useless with the accompanying .wgf though.

I am planning to make a wikipage describing, beside other things, the usage of replays, e.g. they have to be zipped together before uploading and link that wikipage in the upload form. But i have to check for .wrpl.wgf.

Revision history for this message
kaputtnik (franku) wrote :

I have to stop working on this, other wise i fear to change many other things :-D

Anyway i think this works. wai files need some special treatment though.

Please test on alpha: https://alpha.widelands.org/

review: Needs Resubmitting
559. By kaputtnik

merged with latest changes

560. By kaputtnik

added a Reset File button

561. By kaputtnik

added clamav check; fixed a failure for zip files

Revision history for this message
kaputtnik (franku) wrote :

stonerl, can you install and configure clamav on the server, please?

The current branch implemented a check with clamdscan, which needs a clamav daemon. We can also stick with clamscan, which can be run on demand, but this much slow: A file check last 55 sec. on my machine, whereas clamdscan usually needs only 0,1 sec.

The current branch is not running on alpha, yet. Since i am afk for some some days, i'll shut down alpha now.

Revision history for this message
Toni Förster (stonerl) wrote :

Already installed. ;)

562. By kaputtnik

make virus scan a stand alone validor

563. By kaputtnik

cleanups

Revision history for this message
GunChleoc (gunchleoc) wrote :

1 tiny nit.

I also wonder whether we should disallow map files - it might come in handy if somebody wants some feedback before publishing to the maps section.

Revision history for this message
kaputtnik (franku) wrote :

> I also wonder whether we should disallow map files - it might come in handy if somebody wants some feedback before publishing to the maps section.

I just don't want to have map files in the forum. I 'fear' most (new) users will upload a map in the forum instead in the 'right' place. A Feedback can also be done in the map comments, or by linking a map in the forum and ask there for a feedback. Once there is a fix for bug 357914 'Allow submitters of maps to upload new versions' get implement, it should be fine to not allow maps in forum.

But of course we can remove that part of code and if we get in trouble we can add it again.

564. By kaputtnik

MiB instead of Mb

Revision history for this message
kaputtnik (franku) wrote :

@Toni: Can we have the package 'clamdscan' installed? For some reason it is a recommended package for clamd and we do not install recommended packages by default.

Or is clamd configured to have on-access-scanning enabled? Didn't saw that it is configured like that.

Revision history for this message
Toni Förster (stonerl) wrote :

How do you intend to access clamav? The current mode is via socket:

LocalSocket /var/run/clamav/clamd.ctl

If you'd like, I can add a local TCP daemon on port 3310.

Revision history for this message
Toni Förster (stonerl) wrote :

Stupid me. :-) I installed clamdscan.

565. By kaputtnik

added attachment to admin site of a post

Revision history for this message
kaputtnik (franku) wrote :

Thanks :-)

But the check for clamdscan doesn't work on the server... i know why, but i don't know the underlying cause. Will talk on IRC about that issue when i have some more time.

Just found that map uploading is broken with the changes in this branch. So the code for map uploading needs adapting too...

review: Needs Fixing
566. By kaputtnik

refactored uploading of maps to fit with the FileUploadHandler

567. By kaputtnik

use a setting to enable virus check

568. By kaputtnik

use an absolute path for clamdscan. This is needed on the server

Revision history for this message
kaputtnik (franku) wrote :

Finally i got it (hopefully)

Please check again on alpha... https://alpha.widelands.org/

Revision history for this message
kaputtnik (franku) :
review: Needs Resubmitting
Revision history for this message
GunChleoc (gunchleoc) wrote :

I have tested map upload and attaching to forum.

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Manx thanks :)

I wait only for janus to approve the changes regarding python3. He will look at it next weekend.

569. By kaputtnik

simplified attachment hash

Revision history for this message
kaputtnik (franku) wrote :

Finally this is productive now :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches