Skip to content

Commit 016459a

Browse files
engcom-Foxtrotnaydav
authored andcommitted
security-package/issues/21: reCaptcha is added multiple times to head
1 parent f3a4624 commit 016459a

File tree

12 files changed

+229
-225
lines changed

12 files changed

+229
-225
lines changed

ReCaptchaVersion2Checkbox/Model/Adminhtml/UiConfigProvider.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,6 @@ public function __construct(
3434
$this->scopeConfig = $scopeConfig;
3535
}
3636

37-
/**
38-
* @inheritdoc
39-
*/
40-
public function get(): array
41-
{
42-
$config = [
43-
'rendering' => [
44-
'sitekey' => $this->getPublicKey(),
45-
'size' => $this->getSize(),
46-
'theme' => $this->getTheme(),
47-
'hl' => $this->getLanguageCode(),
48-
],
49-
'invisible' => false,
50-
];
51-
return $config;
52-
}
53-
5437
/**
5538
* Get Google API Website Key
5639
*
@@ -96,4 +79,21 @@ private function getLanguageCode(): string
9679
self::XML_PATH_LANGUAGE_CODE
9780
);
9881
}
82+
83+
/**
84+
* @inheritdoc
85+
*/
86+
public function get(): array
87+
{
88+
$config = [
89+
'rendering' => [
90+
'sitekey' => $this->getPublicKey(),
91+
'size' => $this->getSize(),
92+
'theme' => $this->getTheme(),
93+
'hl' => $this->getLanguageCode(),
94+
],
95+
'invisible' => false,
96+
];
97+
return $config;
98+
}
9999
}

ReCaptchaVersion2Checkbox/Model/Adminhtml/ValidationConfigProvider.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ public function __construct(
5151
$this->validationConfigFactory = $validationConfigFactory;
5252
}
5353

54-
/**
55-
* @inheritdoc
56-
*/
57-
public function get(): ValidationConfigInterface
58-
{
59-
/** @var ValidationConfigInterface $validationConfig */
60-
$validationConfig = $this->validationConfigFactory->create(
61-
[
62-
'privateKey' => $this->getPrivateKey(),
63-
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
64-
'validationFailureMessage' => $this->getValidationFailureMessage(),
65-
'extensionAttributes' => null,
66-
]
67-
);
68-
return $validationConfig;
69-
}
70-
7154
/**
7255
* Get Google API Secret Key
7356
*
@@ -89,4 +72,21 @@ private function getValidationFailureMessage(): string
8972
(string)$this->scopeConfig->getValue(self::XML_PATH_VALIDATION_FAILURE)
9073
);
9174
}
75+
76+
/**
77+
* @inheritdoc
78+
*/
79+
public function get(): ValidationConfigInterface
80+
{
81+
/** @var ValidationConfigInterface $validationConfig */
82+
$validationConfig = $this->validationConfigFactory->create(
83+
[
84+
'privateKey' => $this->getPrivateKey(),
85+
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
86+
'validationFailureMessage' => $this->getValidationFailureMessage(),
87+
'extensionAttributes' => null,
88+
]
89+
);
90+
return $validationConfig;
91+
}
9292
}

ReCaptchaVersion2Checkbox/Model/Frontend/UiConfigProvider.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,6 @@ public function __construct(
3535
$this->scopeConfig = $scopeConfig;
3636
}
3737

38-
/**
39-
* @inheritdoc
40-
*/
41-
public function get(): array
42-
{
43-
$config = [
44-
'rendering' => [
45-
'sitekey' => $this->getPublicKey(),
46-
'size' => $this->getSize(),
47-
'theme' => $this->getTheme(),
48-
'hl' => $this->getLanguageCode()
49-
],
50-
'invisible' => false,
51-
];
52-
return $config;
53-
}
54-
5538
/**
5639
* Get Google API Website Key
5740
*
@@ -100,4 +83,23 @@ private function getLanguageCode(): string
10083
ScopeInterface::SCOPE_STORE
10184
);
10285
}
86+
87+
/**
88+
* Return frontend UI config for reCAPTCHA v2.
89+
*
90+
* @return array
91+
*/
92+
public function get(): array
93+
{
94+
$config = [
95+
'rendering' => [
96+
'sitekey' => $this->getPublicKey(),
97+
'size' => $this->getSize(),
98+
'theme' => $this->getTheme(),
99+
'hl' => $this->getLanguageCode(),
100+
],
101+
'invisible' => false,
102+
];
103+
return $config;
104+
}
103105
}

ReCaptchaVersion2Checkbox/Model/Frontend/ValidationConfigProvider.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ public function __construct(
5252
$this->validationConfigFactory = $validationConfigFactory;
5353
}
5454

55-
/**
56-
* @inheritdoc
57-
*/
58-
public function get(): ValidationConfigInterface
59-
{
60-
/** @var ValidationConfigInterface $validationConfig */
61-
$validationConfig = $this->validationConfigFactory->create(
62-
[
63-
'privateKey' => $this->getPrivateKey(),
64-
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
65-
'validationFailureMessage' => $this->getValidationFailureMessage(),
66-
'extensionAttributes' => null,
67-
]
68-
);
69-
return $validationConfig;
70-
}
71-
7255
/**
7356
* Get Google API Secret Key
7457
*
@@ -90,4 +73,23 @@ private function getValidationFailureMessage(): string
9073
(string)$this->scopeConfig->getValue(self::XML_PATH_VALIDATION_FAILURE, ScopeInterface::SCOPE_STORE)
9174
);
9275
}
76+
77+
/**
78+
* Return frontend Validation config for reCAPTCHA v2.
79+
*
80+
* @return ValidationConfigInterface
81+
*/
82+
public function get(): ValidationConfigInterface
83+
{
84+
/** @var ValidationConfigInterface $validationConfig */
85+
$validationConfig = $this->validationConfigFactory->create(
86+
[
87+
'privateKey' => $this->getPrivateKey(),
88+
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
89+
'validationFailureMessage' => $this->getValidationFailureMessage(),
90+
'extensionAttributes' => null,
91+
]
92+
);
93+
return $validationConfig;
94+
}
9395
}

ReCaptchaVersion2Invisible/Model/Adminhtml/UiConfigProvider.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,15 @@ public function __construct(
3535
}
3636

3737
/**
38-
* @inheritdoc
38+
* Get language code
39+
*
40+
* @return string
3941
*/
40-
public function get(): array
42+
private function getLanguageCode(): string
4143
{
42-
$config = [
43-
'rendering' => [
44-
'sitekey' => $this->getPublicKey(),
45-
'badge' => $this->getInvisibleBadgePosition(),
46-
'size' => 'invisible',
47-
'theme' => $this->getTheme(),
48-
'hl' => $this->getLanguageCode()
49-
],
50-
'invisible' => true,
51-
];
52-
return $config;
44+
return (string)$this->scopeConfig->getValue(
45+
self::XML_PATH_LANGUAGE_CODE
46+
);
5347
}
5448

5549
/**
@@ -87,14 +81,20 @@ private function getTheme(): string
8781
}
8882

8983
/**
90-
* Get language code
91-
*
92-
* @return string
84+
* @inheritdoc
9385
*/
94-
private function getLanguageCode(): string
86+
public function get(): array
9587
{
96-
return (string)$this->scopeConfig->getValue(
97-
self::XML_PATH_LANGUAGE_CODE
98-
);
88+
$config = [
89+
'rendering' => [
90+
'sitekey' => $this->getPublicKey(),
91+
'badge' => $this->getInvisibleBadgePosition(),
92+
'size' => 'invisible',
93+
'theme' => $this->getTheme(),
94+
'hl'=> $this->getLanguageCode()
95+
],
96+
'invisible' => true,
97+
];
98+
return $config;
9999
}
100100
}

ReCaptchaVersion2Invisible/Model/Adminhtml/ValidationConfigProvider.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,15 @@ public function __construct(
5252
}
5353

5454
/**
55-
* @inheritdoc
55+
* Get validation failure message
56+
*
57+
* @return string
5658
*/
57-
public function get(): ValidationConfigInterface
59+
private function getValidationFailureMessage(): string
5860
{
59-
/** @var ValidationConfigInterface $validationConfig */
60-
$validationConfig = $this->validationConfigFactory->create(
61-
[
62-
'privateKey' => $this->getPrivateKey(),
63-
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
64-
'validationFailureMessage' => $this->getValidationFailureMessage(),
65-
'extensionAttributes' => null,
66-
]
61+
return trim(
62+
(string)$this->scopeConfig->getValue(self::XML_PATH_VALIDATION_FAILURE)
6763
);
68-
return $validationConfig;
6964
}
7065

7166
/**
@@ -79,14 +74,19 @@ private function getPrivateKey(): string
7974
}
8075

8176
/**
82-
* Get validation failure message
83-
*
84-
* @return string
77+
* @inheritdoc
8578
*/
86-
private function getValidationFailureMessage(): string
79+
public function get(): ValidationConfigInterface
8780
{
88-
return trim(
89-
(string)$this->scopeConfig->getValue(self::XML_PATH_VALIDATION_FAILURE)
81+
/** @var ValidationConfigInterface $validationConfig */
82+
$validationConfig = $this->validationConfigFactory->create(
83+
[
84+
'privateKey' => $this->getPrivateKey(),
85+
'remoteIp' => $this->remoteAddress->getRemoteAddress(),
86+
'validationFailureMessage' => $this->getValidationFailureMessage(),
87+
'extensionAttributes' => null,
88+
]
9089
);
90+
return $validationConfig;
9191
}
9292
}

ReCaptchaVersion2Invisible/Model/Frontend/UiConfigProvider.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,16 @@ public function __construct(
3636
}
3737

3838
/**
39-
* @inheritdoc
40-
*/
41-
public function get(): array
42-
{
43-
$config = [
44-
'rendering' => [
45-
'sitekey' => $this->getPublicKey(),
46-
'badge' => $this->getInvisibleBadgePosition(),
47-
'size' => 'invisible',
48-
'theme' => $this->getTheme(),
49-
'hl' => $this->getLanguageCode()
50-
],
51-
'invisible' => true,
52-
];
53-
return $config;
54-
}
55-
56-
/**
57-
* Get Google API Website Key
39+
* Get language code
5840
*
5941
* @return string
6042
*/
61-
private function getPublicKey(): string
43+
private function getLanguageCode(): string
6244
{
63-
return trim((string)$this->scopeConfig->getValue(self::XML_PATH_PUBLIC_KEY, ScopeInterface::SCOPE_WEBSITE));
45+
return (string)$this->scopeConfig->getValue(
46+
self::XML_PATH_LANGUAGE_CODE,
47+
ScopeInterface::SCOPE_STORE
48+
);
6449
}
6550

6651
/**
@@ -76,6 +61,16 @@ private function getInvisibleBadgePosition(): string
7661
);
7762
}
7863

64+
/**
65+
* Get Google API Website Key
66+
*
67+
* @return string
68+
*/
69+
private function getPublicKey(): string
70+
{
71+
return trim((string)$this->scopeConfig->getValue(self::XML_PATH_PUBLIC_KEY, ScopeInterface::SCOPE_WEBSITE));
72+
}
73+
7974
/**
8075
* Get theme
8176
*
@@ -90,15 +85,20 @@ private function getTheme(): string
9085
}
9186

9287
/**
93-
* Get language code
94-
*
95-
* @return string
88+
* @inheritdoc
9689
*/
97-
private function getLanguageCode(): string
90+
public function get(): array
9891
{
99-
return (string)$this->scopeConfig->getValue(
100-
self::XML_PATH_LANGUAGE_CODE,
101-
ScopeInterface::SCOPE_STORE
102-
);
92+
$config = [
93+
'rendering' => [
94+
'sitekey' => $this->getPublicKey(),
95+
'badge' => $this->getInvisibleBadgePosition(),
96+
'size' => 'invisible',
97+
'theme' => $this->getTheme(),
98+
'hl' => $this->getLanguageCode()
99+
],
100+
'invisible' => true,
101+
];
102+
return $config;
103103
}
104104
}

0 commit comments

Comments
 (0)