Skip to content

Commit b1b674a

Browse files
authored
Merge pull request google#315 from google/unbreak-my-build
Unbreak my build
2 parents 116b65f + 1a32c2f commit b1b674a

8 files changed

+40
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.php_cs.cache
2+
/.phpunit.result.cache
23
/build
34
/composer.lock
45
/examples/config.php

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ php:
99
- '5.6'
1010
- '7.0'
1111
- '7.1'
12+
- '7.2'
13+
- '7.3'
1214

1315
before_script:
1416
- composer install

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"php": ">=5.5"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7",
17-
"friendsofphp/php-cs-fixer": "^2.2.20|^2.12",
16+
"phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7.5.11",
17+
"friendsofphp/php-cs-fixer": "^2.2.20|^2.15",
1818
"php-coveralls/php-coveralls": "^2.1"
1919
},
2020
"autoload": {

examples/recaptcha-content-security-policy.php

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,7 @@
3232
// https://developers.google.com/web/fundamentals/security/csp/
3333

3434
// First we generate a pseudorandom nonce for each included or inline script
35-
// Nonce for including the reCAPTCHA library
36-
$recaptchaNonce = base64_encode(openssl_random_pseudo_bytes(16));
37-
// Nonce for our inline code
38-
$inlineNonce = base64_encode(openssl_random_pseudo_bytes(16));
39-
40-
// Note: this is not related to reCAPTCHA, but if you enable a CSP like this
41-
// you either need to include either a nonce or appropriate domain for any
42-
// scripts on the page.
43-
// Nonce for including Google Analytics library.
44-
$gaIncNonce = base64_encode(openssl_random_pseudo_bytes(16));
45-
// Nonce for firing the Google Analytics call
46-
$gaCfgNonce = base64_encode(openssl_random_pseudo_bytes(16));
35+
$nonce = base64_encode(openssl_random_pseudo_bytes(16));
4736

4837
// Send the CSP header
4938
// Try commenting out the various lines to see what effect it has
@@ -56,10 +45,7 @@
5645
"Content-Security-Policy: "
5746
."default-src 'none'; " // By default we will deny everything
5847

59-
."script-src "
60-
." 'nonce-".$recaptchaNonce."' " // nonce allowing the reCAPTCHA library to be included
61-
." 'nonce-".$inlineNonce."' " // nonce for inline page code
62-
." 'nonce-".$gaIncNonce."' 'nonce-".$gaCfgNonce."'; " // nonces for other scripts
48+
."script-src 'nonce-".$nonce."'; " // nonce allowing the reCAPTCHA library and other third-party scripts to be included
6349

6450
."img-src https://www.gstatic.com/recaptcha/ https://www.google-analytics.com; " // allow images from these URLS
6551
."frame-src https://www.google.com/; " // allow frames from this URL
@@ -82,6 +68,10 @@
8268
// reCAPTCHA supports 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
8369
$lang = 'en';
8470

71+
// The v3 API lets you provide some context for the check by specifying an action.
72+
// See: https://developers.google.com/recaptcha/docs/v3
73+
$pageAction = 'examples/csp';
74+
8575
?>
8676
<!DOCTYPE html>
8777
<html lang="en">
@@ -99,7 +89,7 @@
9989
<title>reCAPTCHA demo - Content Security Policy</title>
10090
<header>
10191
<h1>reCAPTCHA demo</h1><h2>Content Security Policy</h2>
102-
<p><a href="/"> Home</a></p>
92+
<p><a href="/">↩️ Home</a></p>
10393
</header>
10494
<main>
10595
<?php
@@ -114,24 +104,24 @@
114104
<p><strong>NOTE:</strong>This is a sample implementation, the score returned here is not a reflection on your Google account or type of traffic. In production, refer to the distribution of scores shown in <a href="https://www.google.com/recaptcha/admin" target="_blank">your admin interface</a> and adjust your own threshold accordingly. <strong>Do not raise issues regarding the score you see here.</strong></p>
115105
<ol id="recaptcha-steps">
116106
<li class="step0">reCAPTCHA script loading</li>
117-
<li class="step1 hidden"><kbd>grecaptcha.ready()</kbd> fired, calling <pre>grecaptcha.execute('<?php echo $siteKey; ?>', {action: 'examples/csp'})'</pre></li>
107+
<li class="step1 hidden"><kbd>grecaptcha.ready()</kbd> fired, calling <pre>grecaptcha.execute('<?php echo $siteKey; ?>', {action: '<?php echo $pageAction; ?>'})'</pre></li>
118108
<li class="step2 hidden">Received token from reCAPTCHA service, sending to our backend with:
119109
<pre class="token">fetch('/recaptcha-v3-verify.php?token=abc123</pre></li>
120110
<li class="step3 hidden">Received response from our backend: <pre class="response">{"json": "from-backend"}</pre></li>
121111
</ol>
122-
<p><a href="/recaptcha-content-security-policy.php"> Try again</a></p>
112+
<p><a href="/recaptcha-content-security-policy.php">⤴️ Try again</a></p>
123113

124114
<!-- Add the nonce for our inline script to this tag -->
125-
<script nonce="<?php echo $inlineNonce; ?>">
115+
<script nonce="<?php echo $nonce; ?>">
126116
var onloadCallback = function() {
127117
const steps = document.getElementById('recaptcha-steps');
128118
grecaptcha.ready(function() {
129119
document.querySelector('.step1').classList.remove('hidden');
130-
grecaptcha.execute('<?php echo $siteKey; ?>', {action: 'examples/csp'}).then(function(token) {
131-
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?action=examples/csp&token=\'' + token;
120+
grecaptcha.execute('<?php echo $siteKey; ?>', {action: '<?php echo $pageAction; ?>'}).then(function(token) {
121+
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?action=<?php echo $pageAction; ?>&token=\'' + token;
132122
document.querySelector('.step2').classList.remove('hidden');
133123

134-
fetch('/recaptcha-v3-verify.php?action=examples/csp&token='+token).then(function(response) {
124+
fetch('/recaptcha-v3-verify.php?action=<?php echo $pageAction; ?>&token='+token).then(function(response) {
135125
response.json().then(function(data) {
136126
document.querySelector('.response').innerHTML = JSON.stringify(data, null, 2);
137127
document.querySelector('.step3').classList.remove('hidden');
@@ -142,12 +132,12 @@
142132
};
143133
</script>
144134
<!-- Add the nonce value for the reCAPTCHA library to its script tag -->
145-
<script async defer src="https://www.google.com/recaptcha/api.js?render=<?php echo $siteKey; ?>&onload=onloadCallback" nonce="<?php echo $recaptchaNonce; ?>"></script>
135+
<script async defer src="https://www.google.com/recaptcha/api.js?render=<?php echo $siteKey; ?>&onload=onloadCallback" nonce="<?php echo $nonce; ?>"></script>
146136

147137
<?php
148138
endif;?>
149139
</main>
150140

151-
<!-- Google Analytics - adding both nonces here for the library and the inline code -->
152-
<script async defer src="https://www.googletagmanager.com/gtag/js?id=UA-123057962-1" nonce="<?php echo $gaIncNonce; ?>"></script>
153-
<script async nonce="<?php echo $gaCfgNonce; ?>">window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123057962-1');</script>
141+
<!-- Google Analytics - adding nonces here for the library and the inline code -->
142+
<script async defer src="https://www.googletagmanager.com/gtag/js?id=UA-123057962-1" nonce="<?php echo $nonce; ?>"></script>
143+
<script async nonce="<?php echo $nonce; ?>">window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123057962-1');</script>

examples/recaptcha-v2-checkbox-explicit.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<header>
6161
<h1>reCAPTCHA demo</h1><h2>"I'm not a robot" checkbox - Explicit render</h2>
62-
<p><a href="/"> Home</a></p>
62+
<p><a href="/">↩️ Home</a></p>
6363
</header>
6464
<main>
6565
<?php
@@ -93,7 +93,7 @@
9393
<h2>Success!</h2>
9494
<kbd><pre><?php var_export($resp);?></pre></kbd>
9595
<p>That's it. Everything is working. Go integrate this into your real project.</p>
96-
<p><a href="/recaptcha-v2-checkbox-explicit.php"> Try again</a></p>
96+
<p><a href="/recaptcha-v2-checkbox-explicit.php">⤴️ Try again</a></p>
9797
<?php
9898
else:
9999
// If it's not successful, then one or more error codes will be returned.
@@ -102,7 +102,7 @@
102102
<kbd><pre><?php var_export($resp);?></pre></kbd>
103103
<p>Check the error code reference at <kbd><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></kbd>.
104104
<p><strong>Note:</strong> Error code <kbd>missing-input-response</kbd> may mean the user just didn't complete the reCAPTCHA.</p>
105-
<p><a href="/recaptcha-v2-checkbox-explicit.php"> Try again</a></p>
105+
<p><a href="/recaptcha-v2-checkbox-explicit.php">⤴️ Try again</a></p>
106106
<?php
107107
endif;
108108
else:

examples/recaptcha-v2-checkbox.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<header>
6161
<h1>reCAPTCHA demo</h1><h2>"I'm not a robot" checkbox</h2>
62-
<p><a href="/"> Home</a></p>
62+
<p><a href="/">↩️ Home</a></p>
6363
</header>
6464
<main>
6565
<?php
@@ -93,7 +93,7 @@
9393
<h2>Success!</h2>
9494
<kbd><pre><?php var_export($resp);?></pre></kbd>
9595
<p>That's it. Everything is working. Go integrate this into your real project.</p>
96-
<p><a href="/recaptcha-v2-checkbox.php"> Try again</a></p>
96+
<p><a href="/recaptcha-v2-checkbox.php">⤴️ Try again</a></p>
9797
<?php
9898
else:
9999
// If it's not successful, then one or more error codes will be returned.
@@ -102,7 +102,7 @@
102102
<kbd><pre><?php var_export($resp);?></pre></kbd>
103103
<p>Check the error code reference at <kbd><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></kbd>.
104104
<p><strong>Note:</strong> Error code <kbd>missing-input-response</kbd> may mean the user just didn't complete the reCAPTCHA.</p>
105-
<p><a href="/recaptcha-v2-checkbox.php"> Try again</a></p>
105+
<p><a href="/recaptcha-v2-checkbox.php">⤴️ Try again</a></p>
106106
<?php
107107
endif;
108108
else:

examples/recaptcha-v2-invisible.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<header>
6161
<h1>reCAPTCHA demo</h1><h2>Invisible</h2>
62-
<p><a href="/"> Home</a></p>
62+
<p><a href="/">↩️ Home</a></p>
6363
</header>
6464
<main>
6565
<?php
@@ -93,7 +93,7 @@
9393
<h2>Success!</h2>
9494
<kbd><pre><?php var_export($resp);?></pre></kbd>
9595
<p>That's it. Everything is working. Go integrate this into your real project.</p>
96-
<p><a href="/recaptcha-v2-invisible.php"> Try again</a></p>
96+
<p><a href="/recaptcha-v2-invisible.php">⤴️ Try again</a></p>
9797
<?php
9898
else:
9999
// If it's not successful, then one or more error codes will be returned.
@@ -102,7 +102,7 @@
102102
<kbd><pre><?php var_export($resp);?></pre></kbd>
103103
<p>Check the error code reference at <kbd><a href="https://developers.google.com/recaptcha/docs/verify#error-code-reference">https://developers.google.com/recaptcha/docs/verify#error-code-reference</a></kbd>.
104104
<p><strong>Note:</strong> Error code <kbd>missing-input-response</kbd> may mean the user just didn't complete the reCAPTCHA.</p>
105-
<p><a href="/recaptcha-v2-invisible.php"> Try again</a></p>
105+
<p><a href="/recaptcha-v2-invisible.php">⤴️ Try again</a></p>
106106
<?php
107107
endif;
108108
else:

examples/recaptcha-v3-request-scores.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
// reCAPTCHA supports 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
4343
$lang = 'en';
4444

45+
// The v3 API lets you provide some context for the check by specifying an action.
46+
// See: https://developers.google.com/recaptcha/docs/v3
47+
$pageAction = 'examples/v3scores';
4548

4649
?>
4750
<!DOCTYPE html>
@@ -60,7 +63,7 @@
6063
<title>reCAPTCHA demo - Request scores</title>
6164
<header>
6265
<h1>reCAPTCHA demo</h1><h2>Request scores</h2>
63-
<p><a href="/"> Home</a></p>
66+
<p><a href="/">↩️ Home</a></p>
6467
</header>
6568
<main>
6669
<?php
@@ -76,22 +79,22 @@
7679
<p><strong>NOTE:</strong>This is a sample implementation, the score returned here is not a reflection on your Google account or type of traffic. In production, refer to the distribution of scores shown in <a href="https://www.google.com/recaptcha/admin" target="_blank">your admin interface</a> and adjust your own threshold accordingly. <strong>Do not raise issues regarding the score you see here.</strong></p>
7780
<ol id="recaptcha-steps">
7881
<li class="step0">reCAPTCHA script loading</li>
79-
<li class="step1 hidden"><kbd>grecaptcha.ready()</kbd> fired, calling <pre>grecaptcha.execute('<?php echo $siteKey; ?>', {action: 'examples/v3scores'})'</pre></li>
82+
<li class="step1 hidden"><kbd>grecaptcha.ready()</kbd> fired, calling <pre>grecaptcha.execute('<?php echo $siteKey; ?>', {action: '<?php echo $pageAction; ?>'})'</pre></li>
8083
<li class="step2 hidden">Received token from reCAPTCHA service, sending to our backend with:
8184
<pre class="token">fetch('/recaptcha-v3-verify.php?token=abc123</pre></li>
8285
<li class="step3 hidden">Received response from our backend: <pre class="response">{"json": "from-backend"}</pre></li>
8386
</ol>
84-
<p><a href="/recaptcha-v3-request-scores.php"> Try again</a></p>
87+
<p><a href="/recaptcha-v3-request-scores.php">⤴️ Try again</a></p>
8588
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo $siteKey; ?>"></script>
8689
<script>
8790
const steps = document.getElementById('recaptcha-steps');
8891
grecaptcha.ready(function() {
8992
document.querySelector('.step1').classList.remove('hidden');
90-
grecaptcha.execute('<?php echo $siteKey; ?>', {action: 'examples/v3scores'}).then(function(token) {
91-
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?action=examples/v3scores&token=\'' + token;
93+
grecaptcha.execute('<?php echo $siteKey; ?>', {action: '<?php echo $pageAction; ?>'}).then(function(token) {
94+
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?action=<?php echo $pageAction; ?>&token=\'' + token;
9295
document.querySelector('.step2').classList.remove('hidden');
9396

94-
fetch('/recaptcha-v3-verify.php?action=examples/v3scores&token='+token).then(function(response) {
97+
fetch('/recaptcha-v3-verify.php?action=<?php echo $pageAction; ?>&token='+token).then(function(response) {
9598
response.json().then(function(data) {
9699
document.querySelector('.response').innerHTML = JSON.stringify(data, null, 2);
97100
document.querySelector('.step3').classList.remove('hidden');

0 commit comments

Comments
 (0)