Skip to content

Commit 5b1d766

Browse files
authored
Merge pull request #25 from jobrad-gmbh/JRAD-2653-Pentest-Finding-Handle-attachments-correctly-for-permissions
JRAD-2653 Restore checks
2 parents 3de96a9 + cc43889 commit 5b1d766

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

addons/snailmail/tests/test_attachment_access.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def test_user_letter_attachment_without_res_fields_created_by_admin(self):
5252

5353
# As user, ensure the attachment itself cannot be read
5454
attachment.invalidate_cache()
55-
# with self.assertRaises(AccessError): # JobRad: We have temporarily deactivated the access check
56-
attachment.with_user(self.user).datas # JobRad: on attachments without res_fields.
55+
with self.assertRaises(AccessError):
56+
attachment.with_user(self.user).datas
5757
# But, as user, the content of the attachment can be read through the letter
5858
self.assertEqual(base64.b64decode(letter.with_user(self.user).attachment_datas), b'foo')
5959

@@ -64,9 +64,8 @@ def test_user_letter_attachment_without_res_fields_created_by_admin(self):
6464

6565
# As user ensure the attachment itself cannot be read
6666
attachment.invalidate_cache()
67-
# JobRad: We have temporarily deactivated the access check on attachments without res_fields.
68-
# with self.assertRaises(AccessError): # JobRad
69-
self.assertEqual(base64.b64decode(attachment.with_user(self.user).datas), b'bar') # JobRad
67+
with self.assertRaises(AccessError):
68+
self.assertEqual(base64.b64decode(attachment.with_user(self.user).datas), b'bar')
7069
# But, as user, the content of the attachment can be read through the letter
7170
self.assertEqual(base64.b64decode(letter.with_user(self.user).attachment_datas), b'bar')
7271

odoo/addons/base/models/ir_attachment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ def check(self, mode, values=None):
429429
self.env['ir.attachment'].flush(['res_model', 'res_id', 'create_uid', 'public', 'res_field'])
430430
self._cr.execute('SELECT res_model, res_id, create_uid, public, res_field FROM ir_attachment WHERE id IN %s', [tuple(self.ids)])
431431
for res_model, res_id, create_uid, public, res_field in self._cr.fetchall():
432-
if not self.env.is_system() and res_field:
433-
raise AccessError(_("Sorry, you are not allowed to access this document."))
434432
if public and mode == 'read':
435433
continue
434+
if not self.env.is_system() and (res_field or (not res_id and create_uid != self.env.uid)):
435+
raise AccessError(_("Sorry, you are not allowed to access this document."))
436436
if not (res_model and res_id):
437437
continue
438438
model_ids[res_model].add(res_id)

0 commit comments

Comments
 (0)