summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2020-06-19 13:02:34 +0000
committerMartin Trigaux <mat@odoo.com>2020-08-17 09:08:23 +0000
commitd5c16492397047ceb97a0879aa61f068a0eeeca8 (patch)
treeea2de631dcabee0a59c22b927ce0b5cbd8d6af12 /addons/web/controllers
parente6e0eafccd483e2b002b45b514181c8ce4238b0d (diff)
[IMP] base,web: _for_xml_id as a safe access point
/web/action/load is the public controller that Should be used by the webclient to fetch actions _for_xml_id is the default access method on actions that implements fields filtering to avoid leaking server action code or other information not needed by the webclient Implementing whitelist of fields that can be access per model
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 6e5bd95432c..1907064bd6b 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -324,12 +324,18 @@ def set_cookie_and_redirect(redirect_url):
redirect.autocorrect_location_header = False
return redirect
-def clean_action(action):
+def clean_action(action, env):
action.setdefault('flags', {})
action_type = action.setdefault('type', 'ir.actions.act_window_close')
if action_type == 'ir.actions.act_window':
- return fix_view_modes(action)
- return action
+ action = fix_view_modes(action)
+
+ # When returning an action, only few information are really usefull
+ return {
+ field: value
+ for field, value in action.items()
+ if field in env[action['type']]._get_readable_fields()
+ }
# I think generate_views,fix_view_modes should go into js ActionManager
def generate_views(action):
@@ -1357,7 +1363,7 @@ class DataSet(http.Controller):
def call_button(self, model, method, args, kwargs):
action = self._call_kw(model, method, args, kwargs)
if isinstance(action, dict) and action.get('type') != '':
- return clean_action(action)
+ return clean_action(action, env=request.env)
return False
@http.route('/web/dataset/resequence', type='json', auth="user")
@@ -1687,7 +1693,7 @@ class Action(http.Controller):
except Exception:
action_id = 0 # force failed read
- base_action = Actions.browse([action_id]).read(['type'])
+ base_action = Actions.browse([action_id]).sudo().read(['type'])
if base_action:
ctx = dict(request.context)
action_type = base_action[0]['type']
@@ -1696,15 +1702,16 @@ class Action(http.Controller):
if additional_context:
ctx.update(additional_context)
request.context = ctx
- action = request.env[action_type].browse([action_id]).read()
+ action = request.env[action_type].sudo().browse([action_id]).read()
if action:
- value = clean_action(action[0])
+ value = clean_action(action[0], env=request.env)
return value
@http.route('/web/action/run', type='json', auth="user")
def run(self, action_id):
- result = request.env['ir.actions.server'].browse([action_id]).run()
- return clean_action(result) if result else False
+ action = request.env['ir.actions.server'].browse([action_id])
+ result = action.run()
+ return clean_action(result, env=action.env) if result else False
class Export(http.Controller):