-
Notifications
You must be signed in to change notification settings - Fork 4
security(studio): allowlist Studio variable-values endpoint #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: security-dci-crvs-cache
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,22 @@ class VariableValueService: | |||||||||||||||||||||||||||||
| def __init__(self, env: Environment): | ||||||||||||||||||||||||||||||
| self.env = env | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def _data_api_pullable_accessors(self): | ||||||||||||||||||||||||||||||
| """cel_accessors whose cached values may be exposed through the API. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Mirrors the Data API allowlist (`spp.cel.variable._get_data_api_pullable_domain`): | ||||||||||||||||||||||||||||||
| only ordinary external-provider variables are returnable; DCI-backed | ||||||||||||||||||||||||||||||
| (inter-registry health/vital) and computed/scoring/aggregate values are | ||||||||||||||||||||||||||||||
| excluded so this endpoint cannot become an oracle for sensitive cached | ||||||||||||||||||||||||||||||
| data. Cache rows are keyed by the variable's cel_accessor. | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| if "spp.cel.variable" not in self.env: | ||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||
| # sudo: the allowlist is system config; API authorization is the scope | ||||||||||||||||||||||||||||||
| # check at the router. The API client user has no spp.cel.variable ACL. | ||||||||||||||||||||||||||||||
| Variable = self.env["spp.cel.variable"].sudo() # nosemgrep: odoo-sudo-without-context | ||||||||||||||||||||||||||||||
| return Variable.search(Variable._get_data_api_pullable_domain()).mapped("cel_accessor") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_values_for_subject( | ||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||
| partner_id: int, | ||||||||||||||||||||||||||||||
|
|
@@ -66,11 +82,15 @@ def get_values_for_subject( | |||||||||||||||||||||||||||||
| return {} | ||||||||||||||||||||||||||||||
| DataValue = self.env["spp.data.value"] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Build domain | ||||||||||||||||||||||||||||||
| # Build domain. Restrict to API-pullable variables and the current | ||||||||||||||||||||||||||||||
| # company so this endpoint cannot disclose sensitive cached values | ||||||||||||||||||||||||||||||
| # (DCI/CRVS, scoring) or cross-company data. | ||||||||||||||||||||||||||||||
| domain = [ | ||||||||||||||||||||||||||||||
| ("subject_model", "=", "res.partner"), | ||||||||||||||||||||||||||||||
| ("subject_id", "=", partner_id), | ||||||||||||||||||||||||||||||
| ("period_key", "=", period_key), | ||||||||||||||||||||||||||||||
| ("company_id", "=", self.env.company.id), | ||||||||||||||||||||||||||||||
| ("variable_name", "in", self._data_api_pullable_accessors()), | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
|
Comment on lines
88
to
94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the requested
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Filter by variable names if specified | ||||||||||||||||||||||||||||||
|
|
@@ -136,11 +156,15 @@ def get_values_for_subjects( | |||||||||||||||||||||||||||||
| return {} | ||||||||||||||||||||||||||||||
| DataValue = self.env["spp.data.value"] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Build domain | ||||||||||||||||||||||||||||||
| # Build domain. Restrict to API-pullable variables and the current | ||||||||||||||||||||||||||||||
| # company (see get_values_for_subject) so sensitive cached values are | ||||||||||||||||||||||||||||||
| # not disclosed in bulk. | ||||||||||||||||||||||||||||||
| domain = [ | ||||||||||||||||||||||||||||||
| ("subject_model", "=", "res.partner"), | ||||||||||||||||||||||||||||||
| ("subject_id", "in", partner_ids), | ||||||||||||||||||||||||||||||
| ("period_key", "=", period_key), | ||||||||||||||||||||||||||||||
| ("company_id", "=", self.env.company.id), | ||||||||||||||||||||||||||||||
| ("variable_name", "in", self._data_api_pullable_accessors()), | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
|
Comment on lines
162
to
168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the requested
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if variable_names and "*" not in variable_names: | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance Optimization: Filter allowlist query by requested variable names
Currently,
_data_api_pullable_accessorsfetches all active external variables from the database, even when the client has requested only a specific subset of variables (e.g.,?variables=age). If the system has a large number of variables, this can lead to unnecessary database load and memory consumption.We can optimize this by passing the optional
variable_nameslist to_data_api_pullable_accessorsand filtering thespp.cel.variablesearch domain when specific variables are requested.