-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(refactor): lockdown frappe.desk.reportview #12713
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
Conversation
is_report = data.get('view') == 'Report' | ||
return data | ||
|
||
def validate_fields(data): |
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.
Looks like all validators changing the data inline without returning the data.
I prefer to go with a class here as we are trying to keep the state of the data
. May be something like
q = QueryBuilder(data)
q.is_valid_query() - says the query is valid or not
q.data - returns me the constructed data that I can use to query
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.
validate_fields
is also called independently from frappe.client.get_list
data.pop('aggregate_function') | ||
|
||
def raise_invalid_field(fieldname): | ||
frappe.throw(_('Field not permitted in query') + ': {0}'.format(fieldname), frappe.DataError) |
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.
frappe.throw(_('Field not permitted in query') + ': {0}'.format(fieldname), frappe.DataError) | |
frappe.throw(_('Field {0} is not permitted in query').format(frapp.bold(fieldname)), frappe.DataError) |
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.
For readability!
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.
Bold will highlight the field and fix readability right?
Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com>
made that choice for readability
if (fieldname.startswith('count(') | ||
or fieldname.startswith('sum(') | ||
or fieldname.startswith('avg(')): | ||
if not fieldname.strip().endswith(')'): |
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.
May be a list of agregator_functions?
allowed_aggregators = ['count', 'sum', 'avg']
for sep in (' as ', ' AS '): | ||
if sep in fieldname: | ||
fieldname = fieldname.split(sep)[0] |
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.
We can use start_index = field.lower().find(' as ')
.
With this we can handle separators with mixed case aswell.
@Mergifyio backport version-13-pre-release |
Command
|
@Mergifyio backport version-12-hotfix |
…se/pr-12713 fix(refactor): lockdown frappe.desk.reportview (bp #12713)
Command
|
This method locks down publicly facing
frappe.desk.reportview.get
andfrappe.client.get_list
to allow only valid fieldnames as parameters.