# HG changeset patch # User Ruslan Ermilov # Date 1359987235 -14400 # Node ID 42750c1b8d1bc355118f211dcacb553ea7cb6168 # Parent eb4f221921fa42f6c880033ada859103e61fbf96 Secure_link: documented newer operation mode. diff --git a/xml/en/docs/http/ngx_http_secure_link_module.xml b/xml/en/docs/http/ngx_http_secure_link_module.xml --- a/xml/en/docs/http/ngx_http_secure_link_module.xml +++ b/xml/en/docs/http/ngx_http_secure_link_module.xml @@ -10,13 +10,35 @@ + rev="2">
-The ngx_http_secure_link_module module (0.7.18+) checks -the validity of the requested link. +The ngx_http_secure_link_module module (0.7.18) +allows to check authenticity of requested links, +protect resources from unauthorized access, +and limit lifetime of links. + + + +The authenticity of a requested link is verified by comparing the +checksum value passed in a request with the value computed +for the request. +If link has a limited lifetime and the time has expired, +the link is considered outdated. +Status of these checks is made available in the +$secure_link variable. + + + +The module provides two alternative operation modes. +The first mode is enabled by the +directive and allows to check authenticity of requested links +as well as protect resources from unauthorized access. +The second mode (0.8.50) is enabled by the + and +directives, and also allows to limit lifetime of links. @@ -28,44 +50,170 @@ configuration parameter.
-
+
+ + +expression + +http +server +location + + +Defines a string with variables from which the +checksum value and lifetime of a link are to be extracted. + + + +Variables used in an expression are usually associated +with a request; see example below. + + + +Checksum value extracted from the string is compared with +MD5 hash value computed for expression defined by the + directive. +If checksums are different, the $secure_link variable +is set to an empty string. +If checksums are the same, lifetime of a link is checked. +If link has a limited lifetime and the time has expired, +the $secure_link variable is set to “0”. +Otherwise, it is set to “1”. +MD5 hash value passed in a request is encoded in +base64url. + +If link has a limited lifetime, an expiration time +is set in seconds since Epoch (Thu, 01 Jan 1970 00:00:00 GMT). +The value is specified in an expression after MD5 hash, +and is separated by comma. +An expiration time passed in a request is made available in +the $secure_link_expires variable for use in +the directive. +If expiration time is not specified, a link has unlimited +lifetime. + + + + + + +expression + +http +server +location + + +Defines an expression for which the MD5 hash value is to +be computed and compared with the value passed in a request. + + + +An expression should contain the secured part of a link (resource) +and a secret ingredient. +If link has a limited lifetime, +an expression should also contain $secure_link_expires. + + + +To prevent unauthorized access, an expression may contain some +information about the client, such as its address and version +of the browser. + + + +Example: -location /p/ { - secure_link_secret some_secret_word; +location /s/ { + secure_link $arg_md5,$arg_expires; + secure_link_md5 "$secure_link_expires$uri$remote_addr secret"; if ($secure_link = "") { return 403; } + + if ($secure_link = "0") { + return 410; + } + + ... } +The link +“/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647” +restricts access to “/s/link” for the client with IP address +127.0.0.1. +The link also has a limited lifetime until January 19, 2038 (GMT). + + + +On UNIX, the md5 request argument value can be obtained as: + +echo -n '2147483647/s/link127.0.0.1 secret' | \ + openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d = + -
+ -
- word location -Defines a secret word used to check the validity of the link. -The full URL of the protected link looks as follows: +Defines a secret word used to check authenticity +of requested links. + + + +The full URI of a requested link looks as follows: -/prefix/hash/link +/prefix/hash/link -where hash is computed as - -md5(link, secret_word); - +where hash is a hexadecimal representation of an +MD5 hash computed for the concatenation of link and secret word, +and prefix is an arbitrary string without slashes. + + + +If requested link passes the authenticity check, +the $secure_link variable is set to the link +extracted from the request URI. +Otherwise, the $secure_link variable +is set to an empty string. -A prefix is an arbitrary string not including a slash. +Example: + +location /p/ { + secure_link_secret secret; + + if ($secure_link = "") { + return 403; + } + + rewrite ^ /secure/$secure_link; +} + +location /secure/ { + internal; +} + +A request of “/p/5e814704a28d9bc1914ff19fa0c4a00a/link” +will be internally redirected to +“/secure/link”. + + + +On UNIX, the hash value for this example can be obtained as: + +echo -n 'linksecret' | openssl md5 -hex + @@ -76,12 +224,19 @@ A prefix is an arbitrary string not incl
- + $secure_link -equals to the link extracted from the full URL. -If hash is incorrect, this variable is set to an empty string. +Status of a link check. +The specific value depends on the selected operation mode. + + +$secure_link_expires + +Lifetime of a link passed in a request; +intended to be used only in the + directive. diff --git a/xml/ru/docs/http/ngx_http_secure_link_module.xml b/xml/ru/docs/http/ngx_http_secure_link_module.xml --- a/xml/ru/docs/http/ngx_http_secure_link_module.xml +++ b/xml/ru/docs/http/ngx_http_secure_link_module.xml @@ -10,13 +10,35 @@ + rev="2">
-Модуль ngx_http_secure_link_module (0.7.18+) проверяет -правильность запрашиваемой ссылки. +Модуль ngx_http_secure_link_module (0.7.18) +позволяет проверять аутентичность запрашиваемых ссылок, +защищать ресурсы от несанкционированного доступа, +а также ограничивать срок действия ссылок. + + + +Правильность запрашиваемой ссылки проверяется сравнением переданного +в запросе значения контрольной суммы со значением, +вычисляемым для запроса. +Если ссылка имеет ограниченный срок действия и он истёк, +ссылка считается устаревшей. +Результат этих проверок делается доступным в переменной +$secure_link. + + + +Модуль реализует два альтернативных режима работы. +В первом режиме, который включается директивой +, можно проверить аутентичность +запрашиваемых ссылок и защитить их от несанкционированного доступа. +Второй режим (0.8.50) включается директивами + и , +и позволяет также ограничить срок действия ссылок. @@ -28,44 +50,170 @@
-
+
+ + +выражение + +http +server +location + + +Задаёт строку с переменными, из которой будет выделено значение +контрольной суммы и время действия ссылки. + + + +Используемые в выражении переменные обычно связаны с запросом; +см. пример ниже. + + + +Выделенное из строки значение контрольной суммы сравнивается со +значением MD5-хэша, вычисляемым для выражения, заданного +директивой . +Если контрольные суммы не совпадают, значением переменной +$secure_link становится пустая строка. +Если контрольные суммы совпадают, проверяется время действия ссылки. +Если срок действия ссылки задан и истёк, переменная +$secure_link получает значение “0”. +В противном случае она получает значение “1”. +Значение MD5-хэш передаётся в запросе закодированным в +base64url. + +Если ссылка имеет ограниченный срок действия, время её действия +задаётся в секундах с начала эпохи (1 января 1970 года 00:00:00 GMT). +Значение указывается в выражении после MD5-хэша +и отделяется от него запятой. +Время действия ссылки, переданное в запросе, делается доступным +в переменной $secure_link_expires для использования +в директиве . +Если время действия ссылки не задано, ссылка имеет неограниченный +срок действия. + + + + + + +выражение + +http +server +location + + +Задаёт выражение, для которого считается значение MD5-хэш, +сравниваемое с переданным в запросе. + + + +Выражение должно содержать защищаемую часть ссылки (ресурс) +и секретную составляющую. +Если ссылка имеет ограниченный срок действия, +выражение также должно содержать $secure_link_expires. + + + +Для предотвращения несанкционированного доступа выражение +может содержать информацию о клиенте, например, его адрес и +версию браузера. + + + +Пример: -location /p/ { - secure_link_secret some_secret_word; +location /s/ { + secure_link $arg_md5,$arg_expires; + secure_link_md5 "$secure_link_expires$uri$remote_addr secret"; if ($secure_link = "") { return 403; } + + if ($secure_link = "0") { + return 410; + } + + ... } +Ссылка +“/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647” +ограничивает доступ к “/s/link” для клиента с IP-адресом +127.0.0.1. +Ссылка также имеет ограниченный срок действия до 19 января 2038 года (GMT). + + + +Значение аргумента запроса md5 на UNIX можно получить так: + +echo -n '2147483647/s/link127.0.0.1 secret' | \ + openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d = + -
+ -
- слово location -Задаёт секретное слово для проверки правильности ссылки. -Полный URL защищённой ссылки выглядит так: +Задаёт секретное слово для проверки аутентичности +запрашиваемых ссылок. + + + +Полный URI запрашиваемой ссылки выглядит так: -/prefix/hash/ссылка +/префикс/хэш/ссылка -где hash считается как - -md5(ссылка, секретное_слово); - +где хэш — MD5-хэш в шестнадцатеричном виде, +вычисленный для конкатенации ссылки и секретного слова, +а префикс — произвольная строка без слэшей. + + + +Если запрашиваемая ссылка проходит проверку на аутентичность, +значением переменной $secure_link становится ссылка, +выделенная из URI запроса. +В противном случае значением переменной $secure_link +становится пустая строка. -Префикс — произвольная строка, не включающая слэш. +Пример: + +location /p/ { + secure_link_secret secret; + + if ($secure_link = "") { + return 403; + } + + rewrite ^ /secure/$secure_link; +} + +location /secure/ { + internal; +} + +По запросу “/p/5e814704a28d9bc1914ff19fa0c4a00a/link” +будет выполнено внутреннее перенаправление на +“/secure/link”. + + + +Значение хэша для данного примера на UNIX можно получить так: + +echo -n 'linksecret' | openssl md5 -hex + @@ -76,12 +224,19 @@ md5(ссылка, секретное_слово);
- + $secure_link -равна ссылке, выделенной из полного URL’а. -Если хэш неверный, то переменная равна пустой строке. +Результат проверки ссылки. +Конкретное значение зависит от выбранного режима работы. + + +$secure_link_expires + +Время действия ссылки, переданное в запросе. +Предназначено исключительно для использования в директиве +.