|
22 | 22 | "change_timestamp_value",
|
23 | 23 | "change_date_value",
|
24 | 24 | "change_timestamp_filter",
|
| 25 | + "check_query_filter", |
25 | 26 | ]
|
26 | 27 |
|
27 | 28 |
|
@@ -420,3 +421,49 @@ def _convert_date_from_string(date_str, key, date_format) -> date:
|
420 | 421 | return datetime.strptime(date_str, date_format).date()
|
421 | 422 | except Exception as e:
|
422 | 423 | raise ERROR_INVALID_PARAMETER_TYPE(key=key, type=date_format)
|
| 424 | + |
| 425 | + |
| 426 | +def check_query_filter(keywords=None) -> callable: |
| 427 | + if keywords is None: |
| 428 | + keywords = [] |
| 429 | + |
| 430 | + def wrapper(func): |
| 431 | + @functools.wraps(func) |
| 432 | + def wrapped_func(cls, params): |
| 433 | + query = params.get("query", {}) |
| 434 | + if "filter" in query: |
| 435 | + for filters in query["filter"]: |
| 436 | + key = filters.get("key", filters.get("k")) |
| 437 | + if key in keywords: |
| 438 | + raise ERROR_INVALID_PARAMETER( |
| 439 | + key=key, reason="Include secure parameter" |
| 440 | + ) |
| 441 | + |
| 442 | + if "group_by" in query: |
| 443 | + for group_bys in query["group_by"]: |
| 444 | + key = group_bys.get("key", group_bys.get("k")) |
| 445 | + if key in keywords: |
| 446 | + raise ERROR_INVALID_PARAMETER( |
| 447 | + key=key, reason="Include secure parameter" |
| 448 | + ) |
| 449 | + |
| 450 | + if "fields" in query: |
| 451 | + value = query["fields"].get("value", query["fields"].get("v")) |
| 452 | + key = value.get("key", value.get("k")) |
| 453 | + if key in keywords: |
| 454 | + raise ERROR_INVALID_PARAMETER( |
| 455 | + key=key, reason="Include secure parameter" |
| 456 | + ) |
| 457 | + |
| 458 | + if "distinct" in query: |
| 459 | + key = query["distinct"] |
| 460 | + if key in keywords: |
| 461 | + raise ERROR_INVALID_PARAMETER( |
| 462 | + key=key, reason="Include secure parameter" |
| 463 | + ) |
| 464 | + |
| 465 | + return func(cls, params) |
| 466 | + |
| 467 | + return wrapped_func |
| 468 | + |
| 469 | + return wrapper |
0 commit comments