Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/option/PhabricatorSecurityConfigOptions.php
12256 views
1
<?php
2
3
final class PhabricatorSecurityConfigOptions
4
extends PhabricatorApplicationConfigOptions {
5
6
public function getName() {
7
return pht('Security');
8
}
9
10
public function getDescription() {
11
return pht('Security options.');
12
}
13
14
public function getIcon() {
15
return 'fa-lock';
16
}
17
18
public function getGroup() {
19
return 'core';
20
}
21
22
public function getOptions() {
23
$doc_href = PhabricatorEnv::getDoclink('Configuring a File Domain');
24
$doc_name = pht('Configuration Guide: Configuring a File Domain');
25
26
$default_address_blacklist = array(
27
// This is all of the IANA special/reserved blocks in IPv4 space.
28
'0.0.0.0/8',
29
'10.0.0.0/8',
30
'100.64.0.0/10',
31
'127.0.0.0/8',
32
'169.254.0.0/16',
33
'172.16.0.0/12',
34
'192.0.0.0/24',
35
'192.0.2.0/24',
36
'192.88.99.0/24',
37
'192.168.0.0/16',
38
'198.18.0.0/15',
39
'198.51.100.0/24',
40
'203.0.113.0/24',
41
'224.0.0.0/4',
42
'240.0.0.0/4',
43
'255.255.255.255/32',
44
45
// And these are the IANA special/reserved blocks in IPv6 space.
46
'::/128',
47
'::1/128',
48
'::ffff:0:0/96',
49
'100::/64',
50
'64:ff9b::/96',
51
'2001::/32',
52
'2001:10::/28',
53
'2001:20::/28',
54
'2001:db8::/32',
55
'2002::/16',
56
'fc00::/7',
57
'fe80::/10',
58
'ff00::/8',
59
);
60
61
$keyring_type = 'custom:PhabricatorKeyringConfigOptionType';
62
$keyring_description = $this->deformat(pht(<<<EOTEXT
63
The keyring stores master encryption keys. For help with configuring a keyring
64
and encryption, see **[[ %s | Configuring Encryption ]]**.
65
EOTEXT
66
,
67
PhabricatorEnv::getDoclink('Configuring Encryption')));
68
69
$require_mfa_description = $this->deformat(pht(<<<EOTEXT
70
By default, this software allows users to add multi-factor authentication to
71
their accounts, but does not require it. By enabling this option, you can
72
force all users to add at least one authentication factor before they can use
73
their accounts.
74
75
Administrators can query a list of users who do not have MFA configured in
76
{nav People}:
77
78
- **[[ %s | %s ]]**
79
EOTEXT
80
,
81
'/people/?mfa=false',
82
pht('List of Users Without MFA')));
83
84
return array(
85
$this->newOption('security.alternate-file-domain', 'string', null)
86
->setLocked(true)
87
->setSummary(pht('Alternate domain to serve files from.'))
88
->setDescription(
89
pht(
90
'By default, this software serves files from the same domain '.
91
'the application is served from. This is convenient, but '.
92
'presents a security risk.'.
93
"\n\n".
94
'You should configure a CDN or alternate file domain to mitigate '.
95
'this risk. Configuring a CDN will also improve performance. See '.
96
'[[ %s | %s ]] for instructions.',
97
$doc_href,
98
$doc_name))
99
->addExample('https://files.phabcdn.net/', pht('Valid Setting')),
100
$this->newOption(
101
'security.hmac-key',
102
'string',
103
'[D\t~Y7eNmnQGJ;rnH6aF;m2!vJ8@v8C=Cs:aQS\.Qw')
104
->setHidden(true)
105
->setSummary(
106
pht('Key for HMAC digests.'))
107
->setDescription(
108
pht(
109
'Default key for HMAC digests where the key is not important '.
110
'(i.e., the hash itself is secret). You can change this if you '.
111
'want (to any other string), but doing so will break existing '.
112
'sessions and CSRF tokens. This option is deprecated. Newer '.
113
'code automatically manages HMAC keys.')),
114
$this->newOption('security.require-https', 'bool', false)
115
->setLocked(true)
116
->setSummary(
117
pht('Force users to connect via HTTPS instead of HTTP.'))
118
->setDescription(
119
pht(
120
"If the web server responds to both HTTP and HTTPS requests but ".
121
"you want users to connect with only HTTPS, you can set this ".
122
"to `true` to make this service redirect HTTP requests to HTTPS.".
123
"\n\n".
124
"Normally, you should just configure your server not to accept ".
125
"HTTP traffic, but this setting may be useful if you originally ".
126
"used HTTP and have now switched to HTTPS but don't want to ".
127
"break old links, or if your webserver sits behind a load ".
128
"balancer which terminates HTTPS connections and you can not ".
129
"reasonably configure more granular behavior there.".
130
"\n\n".
131
"IMPORTANT: A request is identified as HTTP or HTTPS by examining ".
132
"the PHP `%s` variable. If you run Apache/mod_php this will ".
133
"probably be set correctly for you automatically, but if you run ".
134
"as CGI/FCGI (e.g., through nginx or lighttpd), you need to ".
135
"configure your web server so that it passes the value correctly ".
136
"based on the connection type.".
137
"\n\n".
138
"If you configure clustering, note that this ".
139
"setting is ignored by intracluster requests.",
140
"\$_SERVER['HTTPS']"))
141
->setBoolOptions(
142
array(
143
pht('Force HTTPS'),
144
pht('Allow HTTP'),
145
)),
146
$this->newOption('security.require-multi-factor-auth', 'bool', false)
147
->setLocked(true)
148
->setSummary(
149
pht('Require all users to configure multi-factor authentication.'))
150
->setDescription($require_mfa_description)
151
->setBoolOptions(
152
array(
153
pht('Multi-Factor Required'),
154
pht('Multi-Factor Optional'),
155
)),
156
$this->newOption(
157
'uri.allowed-protocols',
158
'set',
159
array(
160
'http' => true,
161
'https' => true,
162
'mailto' => true,
163
))
164
->setSummary(
165
pht(
166
'Determines which URI protocols are valid for links and '.
167
'redirects.'))
168
->setDescription(
169
pht(
170
'When users write comments which have URIs, they will be '.
171
'automatically turned into clickable links if the URI protocol '.
172
'appears in this set.'.
173
"\n\n".
174
'This set of allowed protocols is primarily intended to prevent '.
175
'security issues with "javascript:" and other potentially '.
176
'dangerous URI handlers.'.
177
"\n\n".
178
'This set is also used to enforce valid redirect URIs. '.
179
'This service will refuse to issue a HTTP "Location" redirect '.
180
'to a URI with a protocol not on this set.'.
181
"\n\n".
182
'Usually, "http" and "https" should be present in this set. If '.
183
'you remove one or both protocols, some features which rely on '.
184
'links or redirects may not work.'))
185
->addExample("http\nhttps", pht('Valid Setting'))
186
->setLocked(true),
187
$this->newOption(
188
'uri.allowed-editor-protocols',
189
'set',
190
array(
191
'http' => true,
192
'https' => true,
193
194
// This handler is installed by Textmate.
195
'txmt' => true,
196
197
// This handler is for MacVim.
198
'mvim' => true,
199
200
// Unofficial handler for Vim.
201
'vim' => true,
202
203
// Unofficial handler for Sublime.
204
'subl' => true,
205
206
// Unofficial handler for Emacs.
207
'emacs' => true,
208
209
// This isn't a standard handler installed by an application, but
210
// is a reasonable name for a user-installed handler.
211
'editor' => true,
212
213
// This handler is for Visual Studio Code.
214
'vscode' => true,
215
216
// This is for IntelliJ IDEA.
217
'idea' => true,
218
))
219
->setSummary(pht('Whitelists editor protocols for "Open in Editor".'))
220
->setDescription(
221
pht(
222
'Users can configure a URI pattern to open files in a text '.
223
'editor. The URI must use a protocol on this whitelist.'))
224
->setLocked(true),
225
$this->newOption('remarkup.enable-embedded-youtube', 'bool', false)
226
->setBoolOptions(
227
array(
228
pht('Embed YouTube videos'),
229
pht("Don't embed YouTube videos"),
230
))
231
->setSummary(
232
pht('Determines whether or not YouTube videos get embedded.'))
233
->setDescription(
234
pht(
235
"If you enable this, linked YouTube videos will be embedded ".
236
"inline. This has mild security implications (you'll leak ".
237
"referrers to YouTube) and is pretty silly (but sort of ".
238
"awesome).")),
239
$this->newOption(
240
'security.outbound-blacklist',
241
'list<string>',
242
$default_address_blacklist)
243
->setLocked(true)
244
->setSummary(
245
pht(
246
'Blacklist subnets to prevent user-initiated outbound '.
247
'requests.'))
248
->setDescription(
249
pht(
250
'Users can make requests to other services from '.
251
'service hosts in some circumstances (for example, by '.
252
'creating a repository with a remote URL).'.
253
"\n\n".
254
'This may represent a security vulnerability if services on '.
255
'the same subnet will accept commands or reveal private '.
256
'information over unauthenticated HTTP GET, based on the source '.
257
'IP address. In particular, all hosts in EC2 have access to '.
258
'such a service.'.
259
"\n\n".
260
'This option defines a list of netblocks which requests will '.
261
'never be issued to. Generally, you should list all '.
262
'private IP space here.'))
263
->addExample(array('0.0.0.0/0'), pht('No Outbound Requests')),
264
$this->newOption('security.strict-transport-security', 'bool', false)
265
->setLocked(true)
266
->setBoolOptions(
267
array(
268
pht('Use HSTS'),
269
pht('Do Not Use HSTS'),
270
))
271
->setSummary(pht('Enable HTTP Strict Transport Security (HSTS).'))
272
->setDescription(
273
pht(
274
'HTTP Strict Transport Security (HSTS) sends a header which '.
275
'instructs browsers that the site should only be accessed '.
276
'over HTTPS, never HTTP. This defuses an attack where an '.
277
'adversary gains access to your network, then proxies requests '.
278
'through an unsecured link.'.
279
"\n\n".
280
'Do not enable this option if you serve (or plan to ever serve) '.
281
'unsecured content over plain HTTP. It is very difficult to '.
282
'undo this change once users\' browsers have accepted the '.
283
'setting.')),
284
$this->newOption('keyring', $keyring_type, array())
285
->setHidden(true)
286
->setSummary(pht('Configure master encryption keys.'))
287
->setDescription($keyring_description),
288
);
289
}
290
291
protected function didValidateOption(
292
PhabricatorConfigOption $option,
293
$value) {
294
295
$key = $option->getKey();
296
if ($key == 'security.alternate-file-domain') {
297
298
$uri = new PhutilURI($value);
299
$protocol = $uri->getProtocol();
300
if ($protocol !== 'http' && $protocol !== 'https') {
301
throw new PhabricatorConfigValidationException(
302
pht(
303
"Config option '%s' is invalid. The URI must start with ".
304
"'%s' or '%s'.",
305
$key,
306
'http://',
307
'https://'));
308
}
309
310
$domain = $uri->getDomain();
311
if (strpos($domain, '.') === false) {
312
throw new PhabricatorConfigValidationException(
313
pht(
314
"Config option '%s' is invalid. The URI must contain a dot ('.'), ".
315
"like '%s', not just a bare name like '%s'. ".
316
"Some web browsers will not set cookies on domains with no TLD.",
317
$key,
318
'http://example.com/',
319
'http://example/'));
320
}
321
322
$path = $uri->getPath();
323
if ($path !== '' && $path !== '/') {
324
throw new PhabricatorConfigValidationException(
325
pht(
326
"Config option '%s' is invalid. The URI must NOT have a path, ".
327
"e.g. '%s' is OK, but '%s' is not. This software must be ".
328
"installed on an entire domain; it can not be installed on a path.",
329
$key,
330
'http://devtools.example.com/',
331
'http://example.com/devtools/'));
332
}
333
}
334
}
335
336
337
}
338
339