Design standard or best practices for handling virtual disk files

Asked

Viewed 248 times

1

There are standard or best practices for dealing with upload, storage, file publishing, and access control?

Environmental example:

I have a system that will need to register Calls and News and in both need allow insertion of attachments and then release them for download or viewing in the browser as possible (pdf, txt, in some cases office files).

I will also have an area for direct publication, where the files will be submitted to a "virtual" directory selected by the user, certain user groups will have access to these directories and files, others will not.

They will also be available for download and/or viewing in browser when possible.

There are standards or best practices to deal with this kind of need?
An important detail is that there will be no user access control for a domain. It will be system users only.

1 answer

2


Some of the practices cited below are from other Stack Overflow questions, and some are mine, by empiricism. There is no Microsoft best practice guide. This response should serve as a good guide to good practice, which I intend to update as new questions appear.

There are standard or best practices for dealing with upload, storage, file publishing, and access control?

Sending

  • Make your Controllers manipulate any and all received files;
  • Always try to use forms and decoration [HttpPost] in Actions of your Controller;
  • Try to limit shipping sizes and times;

Storage

  • For uploads of files by users, avoid directories where direct link access can be made, such as the directory Content, for example. Use an externally inaccessible directory;
  • If separating by user, avoid using the user name for directory nomenclature;
  • Upon receiving a file, change your name before saving it. This ensures some security if someone tries to exploit your application’s security issues using the original file name;
  • Before saving, if it is an image file, try resizing the file. If something fails in this resizing, it may not be exactly an image the user sent;
  • Before saving, check that the MIME Type of the file is in fact corresponding to its contents;

Publishing

  • Ever let your users directly access your files in the case of a Download. Provide the user with a link to a Action return a FileResult;
  • Still on the links, do not provide a file with an easily deductible link, such as an entire ID (http://meusitemaroto/Arquivos/1) or else the file name (http://meusitemaroto/Arquivos/MinhaImagem1, http://meusitemaroto/Arquivos/MinhaImagem2). Manages a string random that works as a token or use Guids;

Access Control

  • Following the previous line, make your Action verify access through Attributes. Could be good old [Authorize] or an authorization attribute implemented by you. There are several questions here at Sopt where I teach you to do this;
  • Avoid allowing downloads if the user is not authenticated. If this is not possible, validate each download using authorization tokens and download counters, or even expiring the file after a while.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.