Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Securitytxt/Model/Config/Backend/SecureUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Securitytxt\Model\Config\Backend;

use Magento\Framework\Validator\Exception as ValidatorException;
use Magento\Framework\App\Config\Value;

/**
* Security.txt secure URL validator.
*/
class SecureUrl extends Value
{
/**
* Validate security.txt URL field before saving it.
*
* @return $this
* @throws ValidatorException
*/
public function beforeSave()
{
$url = $this->getValue();
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$isValid = parse_url($url, PHP_URL_SCHEME) === 'https';
if (!$isValid && $url !== '') {
throw new ValidatorException(
__('URL should be in correct format and must start with HTTPS.')
);
}
return $this;
}
}
126 changes: 0 additions & 126 deletions Securitytxt/Model/Config/Backend/Validate.php

This file was deleted.

42 changes: 26 additions & 16 deletions Securitytxt/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,92 @@
<label>Security</label>
</tab>
<section id="magento_securitytxt_securitytxt" translate="label" type="text" sortOrder="520" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<class>separator-top</class>
<label>Security.txt</label>
<tab>security</tab>
<resource>Magento_Securitytxt::config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1"
showInStore="1">
showInStore="0">
<label>General</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1"
showInStore="1">
showInStore="0">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="contact_information" translate="label" type="text" sortOrder="10" showInDefault="1"
showInWebsite="1"
showInStore="1">
showInStore="0">
<label>Contact Information</label>
<field id="email" translate="label comment" type="text" sortOrder="20" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Email</label>
<validate>validate-email</validate>
<backend_model>Magento\Securitytxt\Model\Config\Backend\Validate</backend_model>
</field>
<field id="phone" translate="label comment" type="text" sortOrder="20" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Phone</label>
</field>
<field id="contact_page" translate="label comment" type="text" sortOrder="20" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Contact Page</label>
<validate>validate-url validate-no-html-tags</validate>
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
<comment>Example: https://example.com/security-contact.html</comment>
</field>
<depends>
<field id="magento_securitytxt_securitytxt/general/enabled">1</field>
</depends>
</group>
<group id="other_information" translate="label" type="text" sortOrder="10" showInDefault="1"
showInWebsite="1"
showInStore="1">
showInStore="0">
<label>Other Information</label>
<field id="encryption" translate="label comment" type="text" sortOrder="40" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0" >
<label>Encryption</label>
<validate>validate-url validate-no-html-tags</validate>
<comment>Example: https://example.com/pgp-key.txt</comment>
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
</field>
<field id="acknowledgements" translate="label comment" type="text" sortOrder="50" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Acknowledgements</label>
<validate>validate-url validate-no-html-tags</validate>
<comment>Example: https://example.com/hall-of-fame.html</comment>
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
</field>
<field id="preferred_languages" translate="label comment" type="text" sortOrder="50" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Preferred-Languages</label>
<validate>validate-text validate-no-html-tags</validate>
<comment>Example: en, es, hi, de, fr</comment>
</field>
<field id="hiring" translate="label comment" type="text" sortOrder="50" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Hiring</label>
<validate>validate-url validate-no-html-tags</validate>
<comment>Example: https://example.com/jobs.html</comment>
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
</field>
<field id="policy" translate="label comment" type="text" sortOrder="60" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Policy</label>
<validate>validate-url validate-no-html-tags</validate>
<comment>Example: https://example.com/security-policy.html</comment>
<backend_model>Magento\Securitytxt\Model\Config\Backend\SecureUrl</backend_model>
</field>
<field id="signature_text" translate="label comment" type="textarea" sortOrder="80" showInDefault="1"
showInWebsite="1" showInStore="1">
showInWebsite="1" showInStore="0">
<label>Signature</label>
<validate>validate-no-html-tags</validate>
<comment model="Magento\Securitytxt\Model\Config\Signature"/>
</field>
<depends>
<field id="magento_securitytxt_securitytxt/general/enabled">1</field>
</depends>
</group>
</section>
</system>
</config>
</config>