Skip to content

Conversation

@chienandalu
Copy link
Member

Tracks Authentication Attempts and Prevents Brute-force Attacks

This module registers each request done by users trying to authenticate into
Odoo. If the authentication fails, a counter is increased for the given remote
IP. After a defined number of attempts, Odoo will ban the remote IP and
ignore new requests.

cc @Tecnativa

@yajo yajo added this to the 10.0 milestone Jun 27, 2017
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried also on runbot with a non correct behavior:

  • Login n times until I reach the limit.
  • On last attempt, it gets me to an incorrect "Internal Server Error", and no banned remote is written.
  • Then, I'm able to login again with correct credentials.


* Authentication failed from remote '127.0.0.1'. Login tried : 'admin'.
Attempt 1 / 10.
Attempt 1 / 10.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove indentation? This provokes an incorrect RST syntax. It was correct as it was.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like my editor tried somehow to re-indent it...

Known issues / Roadmap
======================

The ID used to identify a remote request is the IP provided in the request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put * and indent the rest of the lines.

of the user can be wrong, and mainly in the following cases:

* if the Odoo server is behind an Apache / NGinx proxy without redirection,
all the request will be have the value '127.0.0.1' for the REMOTE_ADDR key;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the line

* if the Odoo server is behind an Apache / NGinx proxy without redirection,
all the request will be have the value '127.0.0.1' for the REMOTE_ADDR key;
* If some users are behind the same Internet Service Provider, if a user is
banned, all the other users will be banned too;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the line

'category': 'Tools',
'summary': "Tracks Authentication Attempts and Prevents Brute-force"
" Attacks module",
'author': "GRAP,Odoo Community Association (OCA)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Tecnativa here

<openerp>
<!-- Copyright 2015 GRAP -Sylvain LE GAL
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put directly <odoo noupdate="1">

"Authentication failed from remote '%s'. "
"The remote has been banned. Login tried : '%s'"
"." % (remote, request.params['login']))
banned_remote_obj.create(cursor, SUPERUSER_ID, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You haven't converted this to new API (banned_remote_obj.sudo().create({ ... }))

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is usually named main.py.

attempt_obj = env['res.authentication.attempt']
banned_remote_obj = env['res.banned.remote']
# Get Settings
max_attempts_qty = int(config_obj.search_read(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use config_obj.get_param('auth_brute_force.max_attempt_qty') instead of search_read.

request.session.db, request.params['login'],
request.params['password'])
# Log attempt
cursor.commit()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a commit just after the next instruction, is this commit really needed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It seems that it's not neccesary.

<!-- Copyright 2015 GRAP -Sylvain LE GAL
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data noupdate="1">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the data node and include the noupdate attribute in the odoo node.

string='Description', compute='_compute_description', store=True)

ban_date = fields.Datetime(
string='Ban Date', required=True, default=_default_ban_date)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default=fields.Datetime.now.

def _compute_attempt_ids(self):
for item in self:
attempt_obj = self.env['res.authentication.attempt']
item.attempt_ids = attempt_obj.search_last_failed(item.remote).ids

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the trailing .ids, Odoo allows you to assign a recordset.

@chienandalu
Copy link
Member Author

@pedrobaeza @sylvain-garancher I coded your suggestions and tested functionally in local.

@chienandalu chienandalu force-pushed the 10.0-mig-auth_brute_force branch from 5ac1662 to 18f4dee Compare June 29, 2017 13:35
@pedrobaeza pedrobaeza force-pushed the 10.0-mig-auth_brute_force branch from 18f4dee to e91bdfb Compare July 29, 2017 12:24
@pedrobaeza pedrobaeza merged commit 3a44e06 into OCA:10.0 Jul 29, 2017
@pedrobaeza pedrobaeza deleted the 10.0-mig-auth_brute_force branch July 29, 2017 12:53
@pedrobaeza pedrobaeza mentioned this pull request Jul 29, 2017
63 tasks
yajo pushed a commit to Tecnativa/server-auth that referenced this pull request May 22, 2018
nikunjantala pushed a commit to Nitrokey/odoo-server-auth that referenced this pull request Sep 5, 2022
nikunjantala pushed a commit to Nitrokey/odoo-server-auth that referenced this pull request Sep 28, 2022
nikunjantala pushed a commit to Nitrokey/odoo-server-auth that referenced this pull request Oct 10, 2022
dsolanki-initos pushed a commit to Nitrokey/odoo-server-auth that referenced this pull request Nov 30, 2022
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Merge 15.0 into 15.0.project_MI_465
hitesh-erpharbor pushed a commit to Nitrokey/odoo-server-auth that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants