summaryrefslogtreecommitdiff
path: root/pod/nginx/ngx_http_secure_link_module.pod
blob: d34cc01166ad684505b5a204e42e837d12b577ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
=encoding utf-8

=head1 NAME

ngx_http_secure_link_module - Module ngx_http_secure_link_module




=head1



The C<ngx_http_secure_link_module> module (0.7.18)
is used to check authenticity of requested links,
protect resources from unauthorized access,
and limit link lifetime.





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 a link has a limited lifetime and the time has expired,
the link is considered outdated.
The status of these checks is made available in the
C<$secure_link> variable.





The module provides two alternative operation modes.
The first mode is enabled by the L</secure_link_secret>
directive and is used to check authenticity of requested links
as well as protect resources from unauthorized access.
The second mode (0.8.50) is enabled by the
L</secure_link> and L</secure_link_md5>
directives and is also used to limit lifetime of links.





This module is not built by default, it should be enabled with the
C<--with-http_secure_link_module>
configuration parameter.




=head1 Directives

=head2 secure_link


B<syntax:> secure_link I<I<C<expression>>>



B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





Defines a string with variables from which the
checksum value and lifetime of a link will be extracted.





Variables used in an I<C<expression>> are usually associated
with a request; see example below.





The checksum value extracted from the string is compared with
the MD5 hash value of the expression defined by the
L</secure_link_md5> directive.
If the checksums are different, the C<$secure_link> variable
is set to an empty string.
If the checksums are the same, the link lifetime is checked.
If the link has a limited lifetime and the time has expired,
the C<$secure_link> variable is set to “C<0>”.
Otherwise, it is set to “C<1>”.
The MD5 hash value passed in a request is encoded in
L<base64url|https://datatracker.ietf.org/doc/html/rfc4648#section-5>.





If a link has a limited lifetime, the expiration time
is set in seconds since Epoch (Thu, 01 Jan 1970 00:00:00 GMT).
The value is specified in the expression after the MD5 hash,
and is separated by a comma.
The expiration time passed in a request is available through
the C<$secure_link_expires> variable for a use in
the L</secure_link_md5> directive.
If the expiration time is not specified, a link has the unlimited
lifetime.







=head2 secure_link_md5


B<syntax:> secure_link_md5 I<I<C<expression>>>



B<context:> I<http>


B<context:> I<server>


B<context:> I<location>





Defines an expression for which the MD5 hash value will
be computed and compared with the value passed in a request.





The expression should contain the secured part of a link (resource)
and a secret ingredient.
If the link has a limited lifetime,
the expression should also contain C<$secure_link_expires>.





To prevent unauthorized access, the expression may contain some
information about the client, such as its address and browser version.





Example:

    
    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
“C<E<sol>sE<sol>link?md5=_e4Nc3iduzkWRm01TBBNYwE<amp>expires=2147483647>”
link
restricts access to “C<E<sol>sE<sol>link>” for the client with the
IP address 127.0.0.1.
The link also has the limited lifetime until January 19, 2038 (GMT).





On UNIX, the I<C<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 =









=head2 secure_link_secret


B<syntax:> secure_link_secret I<I<C<word>>>



B<context:> I<location>





Defines a secret I<C<word>> used to check authenticity
of requested links.





The full URI of a requested link looks as follows:

    
    /<value>prefix</value>/<value>hash</value>/<value>link</value>


where I<C<hash>> is a hexadecimal representation of the
MD5 hash computed for the concatenation of the link and secret word,
and I<C<prefix>> is an arbitrary string without slashes.





If the requested link passes the authenticity check,
the C<$secure_link> variable is set to the link
extracted from the request URI.
Otherwise, the C<$secure_link> variable
is set to an empty string.





Example:

    
    location /p/ {
        secure_link_secret secret;
    
        if ($secure_link = "") {
            return 403;
        }
    
        rewrite ^ /secure/$secure_link;
    }
    
    location /secure/ {
        internal;
    }


A request of “C<E<sol>pE<sol>5e814704a28d9bc1914ff19fa0c4a00aE<sol>link>”
will be internally redirected to
“C<E<sol>secureE<sol>link>”.





On UNIX, the hash value for this example can be obtained as:

    
    echo -n 'linksecret' | openssl md5 -hex









=head1 Embedded Variables




=over



=item C<$secure_link>




The status of a link check.
The specific value depends on the selected operation mode.



=item C<$secure_link_expires>





The lifetime of a link passed in a request;
intended to be used only in the
L</secure_link_md5> directive.




=back