-
Notifications
You must be signed in to change notification settings - Fork 37
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
fix: if no spam protector set, fail sliently #105
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be multiple commits, if not multiple PRs. The changes to composer.json and the code/
(now src/
in this PR) directory are definitely not related to the commit message. Can you please split those out to their own MNT
prefixed commit?
throw new LogicException('No spam protector has been set. Null is not valid value.'); | ||
Requirements::customScript('console.error("No spam protector has been set on this form.")'); | ||
return $this->owner; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change this. As mentioned in #103, when we upgraded this module for CMS 5 compatibility and dropped support for the silverstripe/akismet module we made a conscious decision to leave this exception here - developers should be made aware early on that there's a missing dependency, and may miss a console error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuySartorelli this is for an environment where no recaptcha key is set, that should not kill the entire web page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module doesn't know anything about recaptcha - a separate module would need to be used (e.g. undefinedoffset/silverstripe-nocaptcha) and set as the spam protector following these instructions in the README.
That separate module is then in charge of how it handles missing configuration e.g. missing recaptcha keys.
If you're calling enableSpamProtection()
, then there absolutely should be a protector set - otherwise there has been a developer error. I can't see any way this shouldn't throw an error for the developer to resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuySartorelli I disagree completely (website going down and showing an error to users is absolutely last resort) but I've put my decision behind a config flag for now so it can be toggled off at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm just struggling to understand how you'd get into a situation where this happens on a production website without a developer having encountered the exception first and remedied the configuration... can you please help me understand the scenario in which what would happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is making the following change:
- throw new LogicException('No spam protector has been set. Null is not valid value.');
+ if ($this->config()->get('throw_exception_on_missing_protector')) {
+ throw new LogicException('No spam protector has been set. Null is not valid value.');
+ } else {
+ Injector::inst()->get(LoggerInterface::class)->warning(
+ 'No spam protector has been set. Null is not valid value.'
+ );
+ }
The change is regarding this exception.... what warning are you referring to?
Edit: Sorry, I now realise you mean the console warning in the PR change has been replaced with adding a PHP warning. In some setups that's better than a console error, but in some setups it will be worse, if those aren't being sent to anyone or to some central "hey you need to look at this" service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts from the rest of https://github.com/orgs/silverstripe/teams/core-team?
Throw hard exceptions if it's something is misconfigured so people get immediate feedback is the general philosophy we follow. Silent errors are generally bad, means things can be broken for a long time before anyone realises.
@wilr Sorry to hear about you about woes with your migration, though sounds like what happened there is a lack of testing as part of the migration. I don't see that as a good reason to change our general philosophy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok given the change as now does not change behaviour I don't see any problem merging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem as I see it is that this just doesn't seem like a good change. I don't think we should make it easier to ignore misconfigured environments - and there are already workarounds if you do want to, for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe any of the work arounds are very user friendly. My original comment is still, having no spam protection is better than a broken website.
087da64
to
7099977
Compare
7099977
to
2e6fbf0
Compare
I'm not gonna pick sides here, but 2-3 points from me:
|
@michalkleiner Sure. I've spilt it out now to a new PR as requested (#106) |
Agreed @michalkleiner so I've created a workaround for this project in a
Revelant YAML for anyone who needs it
|
Tidies up the repo to match other modules (cc @GuySartorelli )