New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify captcha throws bad request if captcha not enabled #920

Open
IamSAB opened this Issue Jan 7, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@IamSAB
Copy link

IamSAB commented Jan 7, 2019

Problem

The pagekit 1.0.15 update introducing captcha has a problem. If you apply the @captcha(verify=true) on a route and the captcha is disabled & client is not authenticated, every request will fail.

public function onRequest($event, $request)
    {
        if (!($captcha = $request->attributes->get('_captcha_verify')) || App::user()->isAuthenticated()) {
            return;
        }

        if ($error = $this->verifyToken($request->get('gRecaptchaResponse'), App::module('system/captcha')->config('recaptcha_secret'))) {
            App::abort(400, $error);
        }
    }

It's a logic error in the code. The first if should also check, if the captcha is configured! Currently every route which enforces verification will throw 400 if captcha disabled. At loading scripts (in the onScripts function) this is taken into account.

Problems arises when submitting comments anonymously.

Technical Details

  • Pagekit version: 1.0.15
  • Webserver: dev
  • Database: sqlite3
  • PHP Version: 7.1
@ForgottenTales

This comment has been minimized.

Copy link

ForgottenTales commented Jan 16, 2019

This should be top priority ! For me user registration and comments are not working because of mandatory google captchas. This is a complete blocker issues, for me the CMS is unusable if googleCaptchas are required.

@IamSAB

This comment has been minimized.

Copy link

IamSAB commented Jan 17, 2019

Yeah, currently you are forced to use Captcha with the CMS; otherwise as before mentioned, things like submit comments or registration don't work, because you do that when you are not authenticated.

@MalteScharenberg You created the captcha and for you, as you are familiar with it, you could fix it very fast.

I wrote a quick fix ( one way to do). I simply check, if a captcha config value is not set. If it finds falsy configs, the verify option gets disabled.

     'events' => [
		// captcha bug fix (occurs in Pagekit v1.0.15)
		'request' => [function ($event, $request) use ($app) {
			if ($request->attributes->has('_captcha_verify') && 0 < count(Arr::filter($app->config('system/captcha')->toArray(), function ($val) { return !$val; }))) {
				$request->attributes->set('_captcha_verify', false);
			}
		}, -90],
	] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment