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

Add documents #353

Closed
wants to merge 1 commit into from
Closed

Add documents #353

wants to merge 1 commit into from

Conversation

paroga
Copy link
Member

@paroga paroga commented Feb 18, 2015

No description provided.

@wvengen
Copy link
Member

wvengen commented Feb 18, 2015

Interesting idea!

I'm curious what others think: is this the right approach? Do we want to store documents in the database? Does something like this belong in the wiki, or is this ok?

@wvengen
Copy link
Member

wvengen commented Feb 18, 2015

I'm ok with the database, as a first simple step forward.

@@ -75,6 +75,15 @@

add_index "deliveries", ["supplier_id"], name: "index_deliveries_on_supplier_id", using: :btree

create_table "documents", force: true do |t|
t.string "name"
t.binary "content", limit: 16.megabyte
Copy link
Member

Choose a reason for hiding this comment

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

content-type?

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 use the filename extension in this case.
IMHO storing the "unsafe" content-type provided by the browser is not much better than using the extension of the file.

Copy link
Member

Choose a reason for hiding this comment

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

True 👍

@wvengen
Copy link
Member

wvengen commented Feb 18, 2015

It seems to me that some attachment code is bound to be duplicated in invoice attachments and here. Mime-type-checking, removing attachments, perhaps file-size error handling. I think we'd need to either our own concerns, or use some existing gem. Perhaps this attachment_fu is useful, it's one that is still being maintained (and seems to support full db storage).

@wvengen
Copy link
Member

wvengen commented Feb 27, 2015

Ok, testing it now and doing some small changes. I've done some changes and rebased on master (whoops - can't do a pull request anymore to you) - it's on https://github.com/wvengen/foodsoft/tree/feature/documents . You may consider starting from there.

One thing that I found very unintuitive is that mime-type is derived from the name. I entered a description there without extension, which meant the mimetype couldn't be guessed. So I think it works better when the mimetype is derived either from what the browser sends, or from the original filename. I guess we'd better save it in the db.

@paroga
Copy link
Member Author

paroga commented Feb 27, 2015

i'd prefer the browser content type solution. should I do this change?
one other point in your changes: adding the translations to the en file in the plugins directory had no effect at my installation. only the en file in the core worked. the de translations worked correctly in the plugin folder. Is this a problem with my installation or a general problem?

@wvengen
Copy link
Member

wvengen commented Feb 27, 2015

I'm for the browser content-type solution as well. Would be great, yes.
Hmmm I could see the changes in the plugin locales right away, strange.
(The idea is to put the English locales in the plugin, and then to import them into main Foodsoft as well so that they can easily be translated using localeapp.)

@wvengen
Copy link
Member

wvengen commented Mar 20, 2015

fyi: for the Travis CI build to succeed, you need to bundle install and commit the Gemfile.lock changes.

@Tamriel
Copy link

Tamriel commented Apr 10, 2015

What has to be done to complete this issue?

@wvengen
Copy link
Member

wvengen commented Apr 10, 2015

Thanks for asking, I see the following issues:

  • Security - see OWASP on Unrestricted File Upload
    • Never accept a filename and its extension directly without having a white-list filter.
    • All the control characters and Unicode ones should be removed from the filenames and their extensions without any exception
  • Rebase on master

For the rest, I'd say - all set.
Would it be ok to not enable this plugin by default just yet? I'd like to have more clarity first if sysadmins agree on putting files in the database. You may ask it on the -dev or -discuss mailing list yourself, if you like.

@wvengen wvengen added the plugin label Dec 16, 2015
@wvengen wvengen force-pushed the master branch 2 times, most recently from 8100b26 to d6bf09b Compare February 18, 2016 22:52
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 20, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 23, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 23, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 24, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 24, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Feb 25, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Mar 4, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Mar 4, 2016
@wvengen wvengen mentioned this pull request Mar 4, 2016
paroga added a commit to paroga/foodsoft that referenced this pull request Mar 4, 2016
@paroga
Copy link
Member Author

paroga commented May 5, 2016

ping

if params[:document][:name] == ''
name = params[:document][:data].original_filename
name = File.basename(name)
@document.name = name.gsub(/[^\w\.\-]/, '_')
Copy link
Member

Choose a reason for hiding this comment

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

Great you added a check. Still it's easy to bypass when supplying a name parameter directly.
What about doing this substitution on serving the file? That way we can even change what characters to allow afterwards.

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 do not want to store the original_filename in the DB, so storing a more or less valid name (if not provided by the user already) seams more reasonable to me. This is not related to security. It's just for providing nice filenames.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see.
I'd really like to follow OWASP and filter filename characters to known safe ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

blacklisting as bad practice and whitelisting all unicode characters gets ugly very quickly. What's the problem with storing mad filenames? The only place where it could be problematic is when the browser reads the filename from the HTTP header and when the user uses a browser which is not able to to the without security impact (s)he might have even bigger problems than that!

wvengen pushed a commit that referenced this pull request May 6, 2016
@wvengen
Copy link
Member

wvengen commented May 6, 2016

Great! Disabled it by default, updated the plugin's README and merged.
Thanks a lot!

@wvengen wvengen closed this May 6, 2016
wvengen pushed a commit that referenced this pull request May 6, 2016
@paroga paroga deleted the documents branch September 15, 2016 17:05
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.

3 participants