Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions auth_signup_verify_email/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

from email_validator import EmailSyntaxError, EmailUndeliverableError, validate_email
from werkzeug.exceptions import NotFound

from odoo.http import request, route

Expand All @@ -20,12 +21,19 @@ def web_auth_signup(self, *args, **kw):
return super().web_auth_signup(*args, **kw)

def passwordless_signup(self):
values = request.params
qcontext = self.get_auth_signup_qcontext()

# Same guards as core's web_auth_signup
if not qcontext.get("token") and not qcontext.get("signup_enabled"):
raise NotFound()
if qcontext.get("error"):
return request.render("auth_signup.signup", qcontext)
Comment on lines +27 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · GET requests create accounts

When signup is enabled and a GET request includes a login parameter but no password, web_auth_signup sends any request with a login and no password to passwordless_signup, which proceeds to signup() without checking the HTTP method. A GET request can therefore create an account and send an activation email instead of only displaying the signup form.

Only run passwordless signup for POST requests; render the signup page for GET requests.

Prompt for AI agents
In `auth_signup_verify_email/controllers/main.py` at lines 27-30:

**GET requests create accounts**

When signup is enabled and a GET request includes a `login` parameter but no `password`, `web_auth_signup` sends any request with a `login` and no `password` to `passwordless_signup`, which proceeds to `signup()` without checking the HTTP method. A GET request can therefore create an account and send an activation email instead of only displaying the signup form.

Only run passwordless signup for POST requests; render the signup page for GET requests.


login = request.params.get("login", "")

# Check good format of e-mail
try:
validate_email(values.get("login", ""))
validate_email(login)
except EmailSyntaxError as error:
qcontext["error"] = getattr(
error,
Expand All @@ -39,29 +47,25 @@ def passwordless_signup(self):
except Exception as error: # noqa: BLE001
qcontext["error"] = str(error)
return request.render("auth_signup.signup", qcontext)
if not values.get("email"):
values["email"] = values.get("login")

# remove values that could raise "Invalid field '*' on model 'res.users'"
values.pop("redirect", "")
values.pop("token", "")

# Remove password
values["password"] = ""
# Only pass the fields the signup form is meant to set: request
# params go to a sudo copy() of the template user
values = {
"login": login,
"name": request.params.get("name"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Signup rejects missing names

When a signup POST omits the name parameter, request.params.get("name") adds name: None to values, so signup() overrides the copied template user's name and required-name validation rejects account creation; the caller sees a signup error.

Add name to values only when the POST supplies it.

Also at auth_signup_verify_email/controllers/main.py:56.

Prompt for AI agents
In `auth_signup_verify_email/controllers/main.py` at line 55:

**Signup rejects missing names**

When a signup POST omits the `name` parameter, `request.params.get("name")` adds `name: None` to `values`, so `signup()` overrides the copied template user's name and required-name validation rejects account creation; the caller sees a signup error.

Add `name` to `values` only when the POST supplies it.

Also at `auth_signup_verify_email/controllers/main.py:56`.

"email": request.params.get("email") or login,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Unverified login addresses can be claimed

When an unauthenticated caller submits a valid, unclaimed victim address as login and an attacker-controlled address as email while public signup is enabled, passwordless_signup validates login but stores the caller-supplied email; reset_password(login) then sends the activation link to that stored address. An attacker can register an unclaimed victim address as the login while receiving its activation link, enabling identity squatting and impersonation.

Set the signup email to the validated login, or validate that any separately accepted email is the same address whose ownership must be verified.

Prompt for AI agents
In `auth_signup_verify_email/controllers/main.py` at line 56:

**Unverified login addresses can be claimed**

When an unauthenticated caller submits a valid, unclaimed victim address as `login` and an attacker-controlled address as `email` while public signup is enabled, `passwordless_signup` validates `login` but stores the caller-supplied `email`; `reset_password(login)` then sends the activation link to that stored address. An attacker can register an unclaimed victim address as the login while receiving its activation link, enabling identity squatting and impersonation.

Set the signup email to the validated login, or validate that any separately accepted email is the same address whose ownership must be verified.

"password": "",
}
sudo_users = request.env["res.users"].with_context(create_user=True).sudo()

try:
with request.env.cr.savepoint():
sudo_users.signup(values, qcontext.get("token"))
sudo_users.reset_password(values.get("login"))
sudo_users.reset_password(login)
except Exception:
# Duplicate key or wrong SMTP settings, probably
_logger.exception("Passwordless signup failed")
if (
request.env["res.users"]
.sudo()
.search([("login", "=", qcontext.get("login"))])
):
if request.env["res.users"].sudo().search([("login", "=", login)]):
qcontext["error"] = self.env._(
"Another user is already registered using this email address."
)
Expand Down
53 changes: 40 additions & 13 deletions auth_signup_verify_email/tests/test_verify_email.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from lxml.html import document_fromstring
from unittest.mock import patch

try:
from unittest.mock import patch
except ImportError:
from unittest.mock import patch
from lxml.html import document_fromstring

from odoo.tests.common import HttpCase
from odoo.tools.misc import mute_logger
Expand All @@ -17,19 +14,21 @@
class UICase(HttpCase):
def setUp(self):
super().setUp()
# since 20.0 the website model is declared in base, so its presence in
# the registry no longer tells whether the website module is installed
if "auth_signup_uninvited" in self.env["website"]._fields:
# Enable public signup in website if it is installed; otherwise
# tests here would fail
current_website = self.env.website or self.env.ref("base.default_website")
current_website.auth_signup_uninvited = "b2c"
self.env["ir.config_parameter"].set_str("auth_signup.invitation_scope", "b2c")
self.set_signup_scope("b2c")
self.data = {
"csrf_token": self.csrf_token(),
"name": "Somebody",
}

def set_signup_scope(self, scope):
# since 20.0 the website model is declared in base, so its presence in
# the registry no longer tells whether the website module is installed
if "auth_signup_uninvited" in self.env["website"]._fields:
# Public signup is configured per website when it is installed
current_website = self.env.website or self.env.ref("base.default_website")
current_website.auth_signup_uninvited = scope
self.env["ir.config_parameter"].set_str("auth_signup.invitation_scope", scope)

def html_doc(self, url="/web/signup", data=None, timeout=30):
"""Get an HTML LXML document."""
with patch(mail_template.__name__ + ".MailTemplate.send_mail"):
Expand All @@ -41,6 +40,13 @@ def csrf_token(self):
doc = self.html_doc()
return doc.xpath("//input[@name='csrf_token']")[0].get("value")

def test_signup_page_hides_password(self):
"""Uninvited users sign up without choosing a password."""
doc = self.html_doc()
self.assertTrue(doc.xpath('//input[@name="login"]'))
self.assertFalse(doc.xpath('//input[@name="password"]'))
self.assertFalse(doc.xpath('//input[@name="confirm_password"]'))

def test_bad_email(self):
"""Test rejection of bad emails."""
self.data["login"] = "bad email"
Expand All @@ -54,6 +60,27 @@ def test_good_email(self):
doc = self.html_doc(data=self.data)
self.assertTrue(doc.xpath('//p[@class="alert alert-success"]'))

@mute_logger("odoo.addons.auth_signup_verify_email.controllers.main")
def test_extra_params_ignored(self):
"""Only the signup form fields reach the new user."""
self.data["login"] = "contributors@odoo-community.org"
self.data["ref"] = "injected"
self.html_doc(data=self.data)
user = self.env["res.users"].search([("login", "=", self.data["login"])])
self.assertTrue(user, "signup should have created the user")
self.assertFalse(user.ref)

def test_signup_disabled(self):
"""Passwordless signup follows core's 404 when signup is disabled."""
self.set_signup_scope("b2b")
self.data["login"] = "contributors@odoo-community.org"
with patch(mail_template.__name__ + ".MailTemplate.send_mail"):
resp = self.url_open("/web/signup", data=self.data, timeout=30)
self.assertEqual(resp.status_code, 404)
self.assertFalse(
self.env["res.users"].search([("login", "=", self.data["login"])])
)

@mute_logger("odoo.addons.auth_signup_verify_email.controllers.main")
def test_activation_page_asks_for_password(self):
"""The page linked in the activation email must let you set a password.
Expand Down
11 changes: 4 additions & 7 deletions auth_signup_verify_email/views/signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="signup_fields" inherit_id="auth_signup.fields">
<xpath expr="//div[hasclass('field-password')]" position="attributes">
<xpath
expr="//div[hasclass('field-password')][label[@for='password']]"
position="attributes"
>
<attribute name="t-if">token and not invalid_token</attribute>
</xpath>
<xpath expr="//div[hasclass('field-confirm_password')]" position="attributes">
<attribute name="t-if">token and not invalid_token</attribute>
</xpath>
</template>

<template id="signup_login_fields" inherit_id="auth_signup.signup">
<xpath expr="//input[@name='login']" position="attributes">
<attribute name="type">email</attribute>
</xpath>
</template>
</odoo>