Adding honeypot to BetterComments crashed site

As a follow-up on the suggestion to add a honeypot to a form in post: Site has over 100 pages and 3 of them receiving rampant comment spam. Bizarre!

I added

fields:
    honeypot:
      type: honeypot

to the bettercomments.yaml file and it has essentially crashed the entire site.

Then I undid the edits and reuploaded the file and the site is still crashed!

I deactivated the plugin and the site is still crashed! :angry:

Fatal error : Uncaught RocketTheme\Toolbox\Compat\Yaml\Exception\ParseException: Unable to parse at line 11 (near " -"). in /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php:288 Stack trace: #0 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(320): RocketTheme\Toolbox\Compat\Yaml\Parser->doParse(‘bettercomments’, false, false, false) #1 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(246): RocketTheme\Toolbox\Compat\Yaml\Parser->parseBlock(9, ‘name: bettercom…’, false, false, false) #2 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(78): RocketTheme\Toolbox\Compat\Yaml\Parser->doParse(Array, false, false, false) #3 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Yaml.php(65): RocketTheme\Toolbox\Compat\Yaml\Parser->parse(‘enabled: true\ne…’, false, fal in /home/customer/www/wittmantailwind.com/public_html/system/src/Grav/Common/File/CompiledFile.php on line 105

I can’t even access the admin anymore.

Fatal error : Uncaught RocketTheme\Toolbox\Compat\Yaml\Exception\ParseException: Indentation problem at line 20 (near " -"). in /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php:461 Stack trace: #0 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(246): RocketTheme\Toolbox\Compat\Yaml\Parser->getNextEmbedBlock() #1 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(320): RocketTheme\Toolbox\Compat\Yaml\Parser->doParse(‘bettercomments’, false, false, false) #2 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(246): RocketTheme\Toolbox\Compat\Yaml\Parser->parseBlock(9, ‘name: bettercom…’, false, false, false) #3 /home/customer/www/wittmantailwind.com/public_html/vendor/rockettheme/toolbox/Compat/src/Yaml/Parser.php(78): RocketTheme\Toolbox\Compat\Yaml\Parser->doParse(Array, false, false, false) #4 /home/cus in /home/customer/www/wittmantailwind.com/public_html/system/src/Grav/Common/File/CompiledFile.php on line 105

@Alpha,

See the error log:

  • Unable to parse at line 11 (near " -").
  • Parser->doParse(‘bettercomments’, false, false, false)

You are using a different field format than bettercomments.yaml does.

Can you explain specifically what “You are using a different field format than bettercomments.yaml does” means?

I haven’t changed any fields. I made one simple edit to bettercomments.yaml which crashed the site. I then re-uploaded the previous version that was working before it got edited, but the site has remained crashed. I deleted everything inside the /cache/ directory which didn’t fix anything.

FWIW, here’s my bettercomments.yaml file…

enabled: true
enable_on_routes:
  - /
disable_on_routes:
  - '//archive*'
  - /blog/blog-post-to-ignore
form:
  name: bettercomments
  fields:
    -
      name: name
      label: PLUGIN_COMMENTS.NAME_LABEL
      placeholder: PLUGIN_COMMENTS.NAME_PLACEHOLDER
      autocomplete: 'on'
      type: text
      validate:
        required: true
    -
      name: email
      label: PLUGIN_COMMENTS.EMAIL_LABEL
      placeholder: PLUGIN_COMMENTS.EMAIL_PLACEHOLDER
      type: email
      validate:
        required: true
    -
      name: text
      label: PLUGIN_COMMENTS.MESSAGE_LABEL
      placeholder: PLUGIN_COMMENTS.MESSAGE_PLACEHOLDER
      type: textarea
      validate:
        required: true
    -
      name: date
      type: hidden
      process:
        fillWithCurrentDateTime: true
    -
      name: title
      type: hidden
      evaluateDefault: grav.page.header.title
    -
      name: lang
      type: hidden
      evaluateDefault: grav.language.getLanguage
    -
      name: path
      type: hidden
      evaluateDefault: grav.uri.path
    -
      name: g-recaptcha-response
      label: Captcha
      type: captcha
      recatpcha_site_key: 6L-my-private-key4OEyOP-AOPhna
      recaptcha_not_validated: 'Captcha not valid!'
      validate:
        required: true
  buttons:
    -
      type: submit
      value: PLUGIN_COMMENTS.SUBMIT_COMMENT_BUTTON_TEXT
    -
      type: reset
      value: Reset
  process:
    -
      email:
        subject: PLUGIN_COMMENTS.EMAIL_NEW_COMMENT_SUBJECT
        body: '{% include ''forms/data.html.twig'' %}'
    -
      addComment: null
    -
      message: PLUGIN_COMMENTS.THANK_YOU_MESSAGE
    -
      reset: true

@Alpha, The site is still showing the same error, containing the same hints…

Do you perhaps have multiple bettercomments.yaml versions? Possible locations are (in fallback order):

  1. /user/env/wittmantailwind.com/config/plugins/bettercomments.yaml
    or /user/wittmantailwind.com/config/plugins/bettercomments.yaml
  2. /user/config/plugins/bettercomments.yaml
  3. /user/plugins/bettercomments/bettercomments.yaml

Have you tried: $ bin/grav yamllinter -a

The main plugin is located in user/plugins/bettercomments which does contain a bettercomments.yaml file, however I have not made any edits to this.

There is another bettercomments.yaml file located in user/config/plugins and this is the one I have made edits to.

I have not used yamllinter, but I have been validating my files at https://www.yamllint.com/

What continues to make no sense is that the first line of bettercomments.yaml is currently

enabled: false

so I don’t understand why it continues to give that error at line 11.

@Alpha,

What continues to make no sense is that the first line of bettercomments.yaml is currently

How will Grav detect if a plugin is disabled/enabled if it can’t read its config file to begin with?

so I don’t understand why it continues to give that error at line 11.

Site https://www.wittmantailwind.com/ is still showing the same error, which seems to indicate that the site has not been completely reversed to a previous working state.

I don’t have a backup of a previous version. The only edit I made today was to the bettercomments.yaml file and it was the addition of literally only three lines near the top of it. That instantly caused the error so I restored the file to the previous version. That’s it and now I’ve spent the next six hours paying the price for that one measly edit that evidently rewrote some other config files. Unbelievable.

I just noticed that the pages inside the site are still working. It’s the homepage that’s broken. And the same thing goes for the admin. All the admin pages work except for the admin’s homepage.

Here’s the most recent error in /logs/grav.log. In fact, this was the error that started it all and no other error has been logged since this.

[2024-01-14 16:20:15] grav.CRITICAL: Template “forms/fields//.html.twig” is not defined in “partials/bettercomments.html.twig” at line 74. - Trace: #0 /home/customer/www/wittmantailwind.com/public_html/system/src/Grav/Common/Service/OutputServiceProvider.php(36): Grav\Common\Twig\Twig->processSite(‘html’)

@Alpha,

[2024-01-14 16:20:15] grav.CRITICAL: Template “forms/fields//.html.twig” is not defined in “partials/bettercomments.html.twig” at line 74. - Trace: #0 /home/customer/www/wittmantailwind.com/public_html/system/src/Grav/Common/Service/OutputServiceProvider.php(36): Grav\Common\Twig\Twig->processSite(‘html’)

The only reason I can think of is that this error occurs when your field definition has an empty type. If you’re editing a live site, someone might have accessed the site at the moment you haven’t yet been able to add the field type.

The site and admin homepages are working again!!!

The solution: I changed the version of PHP running on the server.

It was running 7.4.33. As soon as I downgraded it to 7.3.33 everything worked. That’s all it took. I’ve since restored it back to 7.4.33 and it’s still working.

@Alpha, Although the solution does not explain any of the errors mentioned, its nice to see your site is up and running again…

But you haven’t yet added honeypot to the form haven’t you?

I have not. I’ll get to it in the morning and report back. Today wore me out so I stepped away from the computer.

Please acquire the habits of backing up (or better use version control) and developing on a cloned sandbox site.

Please unmark this as the solution.

Unfortunately I don’t know how to do that. The only way I know how to backup the site is to download the /user/ directory, but it’s over 100mb which isn’t very feasible. That’s why I always save a copy of the file I’m editing so I can reupload it in case the edits crash the site. Still learning here.

I added the honeypot according to the example and that’s why it crashed everything.

Screenshot from 2024-01-15 22-12-49

I reformatted it to match the format used with the rest of the bettercomments.yaml and it works! The form now has a hidden element…

<input aria-hidden="true" type="text" 
style="visibility:hidden;position:absolute!important;height:1px;width:1px;overflow:hidden;clip:rect(1px,1px,1px,1px);" 
class="form-honeybear" name="data[honeypot]" value="">

FWIW, the first few lines of bettercomments.yaml looked like this…

form:
  name: bettercomments
  fields:
    - name: name
      label: PLUGIN_COMMENTS.NAME_LABEL
      placeholder: PLUGIN_COMMENTS.NAME_PLACEHOLDER
      autocomplete: on
      type: text
      validate:
        required: true
    - name: email
      label: PLUGIN_COMMENTS.EMAIL_LABEL
      placeholder: PLUGIN_COMMENTS.EMAIL_PLACEHOLDER
      type: email
      validate:
        required: true

When I added the honeypot code to it, I basically copy/pasted it from the user manual so it looked like this…

form:
  name: bettercomments
  fields:
    - honeypot:
        type: honeypot
    - name: name
      label: PLUGIN_COMMENTS.NAME_LABEL
      placeholder: PLUGIN_COMMENTS.NAME_PLACEHOLDER
      autocomplete: on
      type: text
      validate:
        required: true
    - name: email
      label: PLUGIN_COMMENTS.EMAIL_LABEL
      placeholder: PLUGIN_COMMENTS.EMAIL_PLACEHOLDER
      type: email
      validate:
        required: true

To make it work, I had to reformat it like this…

form:
  name: bettercomments
  fields:
    - name: honeypot
      type: honeypot
    - name: name
      label: PLUGIN_COMMENTS.NAME_LABEL
      placeholder: PLUGIN_COMMENTS.NAME_PLACEHOLDER
      autocomplete: on
      type: text
      validate:
        required: true
    - name: email
      label: PLUGIN_COMMENTS.EMAIL_LABEL
      placeholder: PLUGIN_COMMENTS.EMAIL_PLACEHOLDER
      type: email
      validate:
        required: true

Hopefully that helps someone in the future. :+1:t2:

It’s been 24 hours and the honeypot code for bettercomments has not let a single spam message get through. 200+ spams a day down to zero so I’d say it’s working.

1 Like