Skip to content
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Though the experience is not that refined...
# Start the stack in the background
docker compose up -d

# Local Compose disables reCAPTCHA by default. Set RECAPTCHA_ENABLED=true
# only when both the UI site key and API secret are configured.

# Stop the stack and delete all volumes
docker compose down --volumes
```
Expand Down
4 changes: 4 additions & 0 deletions app/Rules/ReCaptchaValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ private function verify($token) {
* @return bool
*/
public function passes($attribute, $value) {
if (config('app.env') === 'local' && config('recaptcha.enabled') === false) {
return true;
}

$recaptchaResponse = $this->verify($value);

if ($this->verifyHostname($recaptchaResponse->getHostname()) === false) {
Expand Down
1 change: 1 addition & 0 deletions config/recaptcha.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [
'enabled' => env('RECAPTCHA_ENABLED', true),
'secret_key' => env('RECAPTCHA_V3_SECRET_KEY', 'config/recaptcha.php: no-secret-key-set!'),
'min_score' => env('RECAPTCHA_V3_MIN_SCORE', 0.5),
];
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- redis
environment:
- CONTAINER_ROLE=app
- RECAPTCHA_ENABLED=${RECAPTCHA_ENABLED:-false}
sql:
image: "${DOCKER_DATABASE_IMAGE_NAME}"
environment:
Expand Down
25 changes: 25 additions & 0 deletions tests/Validation/ReCaptchaValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ public function testBypassFails() {
);
}

public function testRecaptchaCanBeDisabledInLocalDevelopment() {
config([
'app.env' => 'local',
'recaptcha.enabled' => false,
]);

$rule = $this->buildReCaptchaValidation();

$this->assertTrue($rule->passes('token', ''));
}

public function testRecaptchaCannotBeDisabledOutsideLocalDevelopment() {
config([
'app.env' => 'production',
'recaptcha.enabled' => false,
]);

$mockReCaptcha = $this->buildMockedReCaptcha(
$this->buildReCaptchaFakeResponse(['success' => false])
);
$rule = $this->buildReCaptchaValidation($mockReCaptcha);

$this->assertFalse($rule->passes('token', 'someToken'));
}

public function testLowScore() {
$fakeResponse = $this->buildReCaptchaFakeResponse([
'score' => config('recaptcha.min_score') - 1,
Expand Down
Loading