H
H
hAlex2014-02-24 10:18:53
Nginx
hAlex, 2014-02-24 10:18:53

How to prevent file uploads in Nginx?

Good afternoon.
Is it possible in nginx to forbid processing a post that has files?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hAlex, 2014-02-25
@hAlex

This is more suitable
in the context of location (in the server it will probably work too)

if ($content_type ~* form-data) {
  return 404; // Ну или редирект
}

That is, if the request has a contetn-type multipart/form-data, then most likely there is a file, so it's out).
And if there is no file in the form, then set the correct enctype (application/x-www-form-urlencoded) to it and the form will pass.

S
Sergey Sokolov, 2014-02-24
@sergiks

You can forbid accepting POST requests at all, or limit their size:

# не принимать POST вообще
location /nopost/ {
    limit_except  GET HEAD { deny   all; }
}

# не больше 1к данных постом
location /smallpost/ {
    client_max_body_size = 1k;
}

V
Vlad Zhivotnev, 2014-02-24
@inkvizitor68sl

And what is the difference between a regular POST request and a POST request with a file, in your opinion)? That's right, nothing. The file is inserted into request_body in binary form.
So just size. Or completely banned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question