Skip to content

Commit 6fe6899

Browse files
authored
Merge branch '1.0.0-develop' into security-package/issues/188
2 parents 1f58279 + 8aad7b0 commit 6fe6899

File tree

309 files changed

+26673
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

309 files changed

+26673
-148
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Securitytxt\Model\Config\Backend;
9+
10+
use Magento\Framework\Validator\Exception as ValidatorException;
11+
use Magento\Framework\App\Config\Value;
12+
13+
/**
14+
* Security.txt secure URL validator.
15+
*/
16+
class SecureUrl extends Value
17+
{
18+
/**
19+
* Validate security.txt URL field before saving it.
20+
*
21+
* @return $this
22+
* @throws ValidatorException
23+
*/
24+
public function beforeSave()
25+
{
26+
$url = $this->getValue();
27+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
28+
$isValid = parse_url($url, PHP_URL_SCHEME) === 'https';
29+
if (!$isValid && $url !== '') {
30+
throw new ValidatorException(
31+
__('URL should be in correct format and must start with HTTPS.')
32+
);
33+
}
34+
return $this;
35+
}
36+
}

Securitytxt/Model/Config/Backend/Validate.php

Lines changed: 0 additions & 126 deletions
This file was deleted.

Securitytxt/Model/Config/Signature.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,40 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Securitytxt\Model\Config;
109

1110
use Magento\Config\Model\Config\CommentInterface;
11+
use Magento\Framework\Escaper;
1212

1313
/**
1414
* Signature field description
1515
*/
1616
class Signature implements CommentInterface
1717
{
18+
/**
19+
* @var string
20+
*/
21+
private $instructionLink;
22+
23+
/**
24+
* @var Escaper
25+
*/
26+
private $escaper;
27+
28+
/**
29+
* @param Escaper $escaper
30+
* @param string $instructionLink
31+
*/
32+
public function __construct(
33+
Escaper $escaper,
34+
string $instructionLink = ''
35+
) {
36+
$this->escaper = $escaper;
37+
$this->instructionLink = $instructionLink;
38+
}
39+
1840
/**
1941
* Get comment for signature field of security txt extension.
2042
*
@@ -24,8 +46,13 @@ class Signature implements CommentInterface
2446
*/
2547
public function getCommentText($elementValue): string
2648
{
27-
return "<a href='https://devdocs.magento.com/' target='_blank'>
28-
Read instructions on how to generate signature
29-
</a>";
49+
if ($this->instructionLink === '') {
50+
return '';
51+
}
52+
return sprintf(
53+
"<a href='%s' target='_blank'>%s</a>",
54+
$this->escaper->escapeUrl($this->instructionLink),
55+
__('Read instructions on how to generate signature')
56+
);
3057
}
3158
}

Securitytxt/etc/adminhtml/system.xml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,92 @@
1212
<label>Security</label>
1313
</tab>
1414
<section id="magento_securitytxt_securitytxt" translate="label" type="text" sortOrder="520" showInDefault="1"
15-
showInWebsite="1" showInStore="1">
15+
showInWebsite="1" showInStore="0">
1616
<class>separator-top</class>
1717
<label>Security.txt</label>
1818
<tab>security</tab>
1919
<resource>Magento_Securitytxt::config</resource>
2020
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1"
21-
showInStore="1">
21+
showInStore="0">
2222
<label>General</label>
2323
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1"
24-
showInStore="1">
24+
showInStore="0">
2525
<label>Enable</label>
2626
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2727
</field>
2828
</group>
2929
<group id="contact_information" translate="label" type="text" sortOrder="10" showInDefault="1"
3030
showInWebsite="1"
31-
showInStore="1">
31+
showInStore="0">
3232
<label>Contact Information</label>
3333
<field id="email" translate="label comment" type="text" sortOrder="20" showInDefault="1"
34-
showInWebsite="1" showInStore="1">
34+
showInWebsite="1" showInStore="0">
3535
<label>Email</label>
3636
<validate>validate-email</validate>
37-
<backend_model>Magento\Securitytxt\Model\Config\Backend\Validate</backend_model>
3837
</field>
3938
<field id="phone" translate="label comment" type="text" sortOrder="20" showInDefault="1"
40-
showInWebsite="1" showInStore="1">
39+
showInWebsite="1" showInStore="0">
4140
<label>Phone</label>
4241
</field>
4342
<field id="contact_page" translate="label comment" type="text" sortOrder="20" showInDefault="1"
44-
showInWebsite="1" showInStore="1">
43+
showInWebsite="1" showInStore="0">
4544
<label>Contact Page</label>
4645
<validate>validate-url validate-no-html-tags</validate>
46+
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
4747
<comment>Example: https://example.com/security-contact.html</comment>
4848
</field>
49+
<depends>
50+
<field id="magento_securitytxt_securitytxt/general/enabled">1</field>
51+
</depends>
4952
</group>
5053
<group id="other_information" translate="label" type="text" sortOrder="10" showInDefault="1"
5154
showInWebsite="1"
52-
showInStore="1">
55+
showInStore="0">
5356
<label>Other Information</label>
5457
<field id="encryption" translate="label comment" type="text" sortOrder="40" showInDefault="1"
55-
showInWebsite="1" showInStore="1">
58+
showInWebsite="1" showInStore="0" >
5659
<label>Encryption</label>
5760
<validate>validate-url validate-no-html-tags</validate>
5861
<comment>Example: https://example.com/pgp-key.txt</comment>
62+
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
5963
</field>
6064
<field id="acknowledgements" translate="label comment" type="text" sortOrder="50" showInDefault="1"
61-
showInWebsite="1" showInStore="1">
65+
showInWebsite="1" showInStore="0">
6266
<label>Acknowledgements</label>
6367
<validate>validate-url validate-no-html-tags</validate>
6468
<comment>Example: https://example.com/hall-of-fame.html</comment>
69+
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
6570
</field>
6671
<field id="preferred_languages" translate="label comment" type="text" sortOrder="50" showInDefault="1"
67-
showInWebsite="1" showInStore="1">
72+
showInWebsite="1" showInStore="0">
6873
<label>Preferred-Languages</label>
6974
<validate>validate-text validate-no-html-tags</validate>
7075
<comment>Example: en, es, hi, de, fr</comment>
7176
</field>
7277
<field id="hiring" translate="label comment" type="text" sortOrder="50" showInDefault="1"
73-
showInWebsite="1" showInStore="1">
78+
showInWebsite="1" showInStore="0">
7479
<label>Hiring</label>
7580
<validate>validate-url validate-no-html-tags</validate>
7681
<comment>Example: https://example.com/jobs.html</comment>
82+
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
7783
</field>
7884
<field id="policy" translate="label comment" type="text" sortOrder="60" showInDefault="1"
79-
showInWebsite="1" showInStore="1">
85+
showInWebsite="1" showInStore="0">
8086
<label>Policy</label>
8187
<validate>validate-url validate-no-html-tags</validate>
8288
<comment>Example: https://example.com/security-policy.html</comment>
89+
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
8390
</field>
8491
<field id="signature_text" translate="label comment" type="textarea" sortOrder="80" showInDefault="1"
85-
showInWebsite="1" showInStore="1">
92+
showInWebsite="1" showInStore="0">
8693
<label>Signature</label>
8794
<validate>validate-no-html-tags</validate>
8895
<comment model="Magento\Securitytxt\Model\Config\Signature"/>
8996
</field>
97+
<depends>
98+
<field id="magento_securitytxt_securitytxt/general/enabled">1</field>
99+
</depends>
90100
</group>
91101
</section>
92102
</system>
93-
</config>
103+
</config>

Securitytxt/etc/di.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
<argument name="resultPageFactory" xsi:type="object">securitytxtResultPageFactory</argument>
2323
</arguments>
2424
</type>
25-
</config>
25+
<type name="Magento\Securitytxt\Model\Config\Signature">
26+
<arguments>
27+
<argument name="instructionLink" xsi:type="string">
28+
https://github.com/magento/security-package/blob/1.0-develop/Securitytxt/README.md
29+
</argument>
30+
</arguments>
31+
</type>
32+
</config>

Securitytxt/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ Hiring,Hiring
2626
"Example: https://example.com/jobs.html","Example: https://example.com/jobs.html"
2727
Policy,Policy
2828
"Example: https://example.com/security-policy.html","Example: https://example.com/security-policy.html"
29-
Signature,Signature
29+
Signature,Signature
30+
"Read instructions on how to generate signature","Read instructions on how to generate signature"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\TwoFactorAuth\Api;
10+
11+
use Magento\Integration\Api\AdminTokenServiceInterface as OriginalTokenServiceInterface;
12+
13+
/**
14+
* Obtain basic information about the user required to setup or use 2fa
15+
*/
16+
interface AdminTokenServiceInterface extends OriginalTokenServiceInterface
17+
{
18+
19+
}

0 commit comments

Comments
 (0)