Prevent to send web notifications to other users

Only the admin user (sudo) is allowed to send notifications to other
users. The normal users can only send notifications to themselves.

This is to prevent attackers to craft malicious notifications and send
them to other users using RPC.

Correction based on the idea of @hbrunn
This commit is contained in:
Guewen Baconnier
2018-10-08 10:04:36 +02:00
committed by trisdoan
parent 48e68d11d6
commit 2eb3dc7d92
4 changed files with 24 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import exceptions
from odoo.tests import common
from odoo.addons.bus.models.bus import json_dump
import json
@@ -55,3 +56,13 @@ class TestResUsers(common.TransactionCase):
first_pos_call_args = pos_call_args[0]
self.assertIsInstance(first_pos_call_args, list)
self.assertEqual(len(users), len(first_pos_call_args))
def test_notify_other_user(self):
other_user = self.env.ref('base.user_demo')
other_user_model = self.env['res.users'].sudo(other_user)
with self.assertRaises(exceptions.UserError):
other_user_model.browse(self.env.uid).notify_info('hello')
def test_notify_admin_allowed_other_user(self):
other_user = self.env.ref('base.user_demo')
other_user.notify_info('hello')