Skip to content
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

Honeypot Filter #176

Closed
lonnieezell opened this issue Jul 19, 2016 · 15 comments
Closed

Honeypot Filter #176

lonnieezell opened this issue Jul 19, 2016 · 15 comments
Labels
help wanted More help is needed for the proper resolution of an issue or pull request new feature PRs for new features

Comments

@lonnieezell
Copy link
Member

Something like: https://github.com/CHH/stack-honeypot

@lonnieezell lonnieezell added help wanted More help is needed for the proper resolution of an issue or pull request new feature PRs for new features labels Jul 19, 2016
@lonnieezell lonnieezell added this to the Pre-Alpha 2 milestone Jul 19, 2016
@arma7x
Copy link
Contributor

arma7x commented Jul 21, 2016

How about this implementation http://forum.codeigniter.com/thread-63141.html

@InsiteFX
Copy link
Contributor

We do not need to start bloating CI4 with third party add-on stuff.

@lonnieezell
Copy link
Member Author

My thought was that this would replace the ineffective CAPTCHA system we have with something that, as far as I know, is still seen as being fairly effective at stopping bots. And, with filters now in the system, it can be automated so the user never has to think about it.

@arma7x
Copy link
Contributor

arma7x commented Jul 21, 2016

I read simple explanation here. And have try 2 method of implementation,

    1. Extend security class but need form helper to insert honey pot field into form then filter is done like CSRF. My reference http://forum.codeigniter.com/thread-63141.html
    1. Apply directly to filter, before() to validate honey pot and after() to append honey pot at the end of any form field. But using preg_replace() to add honey pot into getBody() output really pain task, what I do is replace by adding honey pot before closed form.
$prep_field = '<div class="hidden" style="display: none;"><input type="hidden" name="'.$this->inputName.'" value="'.$this->inputValue.'" style="display:none;" /></div></form>';
$body = preg_replace('/<\/form>/', $prep_field, $body);

@aanbar
Copy link

aanbar commented Jul 27, 2016

As I understand this cannot replace captcha; this is a method to protect against general purpose spam bots & won't be effective if the bot was written for a specific site.

Anyway, I don't like the idea of having useless form fields in every single form I have so adding it automatically & checking for it automatically may not be convenient for everybody.

How it works:

  • You create a div & add an empty text field and add a class to hide that form field from normal users.
  • You check that the honeypot field which is required to be empty is actually empty upon form submission.

If I understand how it works correctly then here's my suggestion on how to implement this:

  • Add a function in form_helper -- form_honeypot(string $name)
  • either add a function in form_helper like check_honeypot(string $name): bool which returns boolean true when empty or false when it's filled & let the user handle it inside controller
  • Or add a validation rule in form_validation like 'honeypot_field' which would give a generic error message like (Failed to validate form) without giving hints on what's wrong

We might have both options implemented & let the user chose what he wants.
This require adding a user guide on how to use this

@lonnieezell
Copy link
Member Author

Anyway, I don't like the idea of having useless form fields in every single form I have so adding it automatically & checking for it automatically may not be convenient for everybody.

Which is why it would be setup as a filter that users could decide to use or not.

You're how it works section describes the original version. Improvements have been made to the theories that improve it's effectiveness, including randomizing where in the form it's placed, taking the name of an existing form-field, hashing the other on the form, and then putting them back on the way back in, time restrictions, etc. With the newer methods, they seem to be better than many, if not most, captcha's, and leaps above what CI3 provides.

But the newer methods also work best as a filter/middleware so that it can analyze the built form during output and insert/modify the field names, etc, and then put things back and do it's check on the way in.

@lonnieezell lonnieezell modified the milestones: Alpha, Pre-Alpha 2 May 19, 2017
@ranjithsiji
Copy link

ranjithsiji commented Jul 15, 2017

This is a fantastic feature. A must to be included in Codeigniter. Better than CSRF I think. 👍 @aanbar I think you are right. the implementation must have more options. the field may contain some value or a blank.

having useless form fields in every single form I have so adding it automatically & checking for it automatically may not be convenient for everybody.

Yes you are right. But there is always an option to disable this honey pot and it is off by default. If someone wants then just enable honey pot and use it.

I think using this we can raise the security level of Codeigniter by including this feature.

@lonnieezell lonnieezell modified the milestones: Alpha, 4.0 Public Availability Jan 9, 2018
@dvdnwoke
Copy link
Contributor

This is a nice feature is anyone working it currently?

@lonnieezell
Copy link
Member Author

I have made a start on it, but have not gotten very far. If you want to tackle it - that works for me! :)

@dvdnwoke
Copy link
Contributor

The theory i have is adding it as middleware, so that on every request the honeypot field can be checked and redirected to blank page if the fields is not empty and possibility to randomize the field names.

@lonnieezell
Copy link
Member Author

@dvdnwoke That's exactly correct. Though CI4 doesn't have "middleware" by that name. You would use Controller Filters the same way.

@dvdnwoke
Copy link
Contributor

Ok I will implement it over the weekend

@lonnieezell
Copy link
Member Author

Great. I look forward to it!

@dvdnwoke
Copy link
Contributor

dvdnwoke commented May 31, 2018

@lonnieezell
This is what i was able to come up with any suggestion or improvement before sending it as pull request


use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class Honeypot implements FilterInterface {

    /**
	 * Checks if Honeypot field is empty, if so
     * then the requester is a bot,show a blank
     * page
	 *
	 * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
	 *
	 * @return mixed
	 */

    public function before (RequestInterface $request) {

        // **Will there be need to protect against bad data**
        if($request->getVar('honeypot')){
            die();
            //**Is Redirection needed**
        }

        
    }

    /**
	 * Checks if Honeypot field is empty, if so
     * then the requester is a bot,show a blank
     * page
	 *
	 * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
	 * @param ResponseInterface|\CodeIgniter\HTTP\Response $response
	 * @return mixed
	 */

    public function after (RequestInterface $request, ResponseInterface $response) {
        
        $prep_field = '
            <div class="hidden" style="display:none">
                <label>Fill This Trap</label>
                <input type="hidden" name="honeypot" value=""/>
            </div>
            </form>';
        
        $body = $response->getBody();
        $body = preg_replace('/<\/form>/', $prep_field, $body);
        $response->setBody($body);
    }
}

@lonnieezell
Copy link
Member Author

@dvdnwoke That's a good start. Here's a few comments:

  • make the name, label, etc set through a config file so users can easily change it per app. See this class. Oh - and make the base HTML part a template string that can be defined in the config file, also, so user can make it look structurally like the rest of their site if they need to.
  • move the logic to a new class. A simple implementation like you've started here is fine, but somewhere down the road we'll want to make it more robust and more effective. Good ideas here.
  • don't forget docs and tests. :)

Then go ahead an submit a PR and we can go from there.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted More help is needed for the proper resolution of an issue or pull request new feature PRs for new features
Projects
None yet
Development

No branches or pull requests

6 participants