Skip to content

Commit

Permalink
fix(manager): allow UI referer to be other envs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomáš Sasák authored and jdobes committed Nov 27, 2023
1 parent 324554e commit abd185a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import csv
import json
import re
from dataclasses import dataclass
from datetime import datetime
from datetime import timezone
Expand Down Expand Up @@ -63,7 +64,7 @@
CVE_SYNOPSIS_SORT = [fn.SUBSTRING(SQL("cve_name"), r"-(\d+)-").cast("integer"),
fn.SUBSTRING(SQL("cve_name"), r"-(\d+)$").cast("integer")]

UI_REFERER = "console.redhat.com"
UI_REFERER = re.compile("console(.*).redhat.com")
API_SOURCE = "API"
UI_SOURCE = "UI"

Expand Down Expand Up @@ -171,7 +172,7 @@ def auth_common(identity, x_rh_identity): # pylint: disable=unused-argument
rbac_manager = RbacManager()
g.rbac_perms, g.group_ids = rbac_manager.fetch_permissions(x_rh_identity) # pylint: disable=assigning-non-slot

ACCOUNT_REQUESTS.labels(org_id, UI_SOURCE if UI_REFERER in connexion.request.headers.get("referer", "") else API_SOURCE).inc()
ACCOUNT_REQUESTS.labels(org_id, UI_SOURCE if UI_REFERER.search(connexion.request.headers.get("referer", "")) else API_SOURCE).inc()
return {"uid": {"account_number": account_number, "org_id": org_id}}


Expand Down Expand Up @@ -276,7 +277,7 @@ def _parse_list_arguments(cls, kwargs):
if data_format not in ["json", "csv"]:
raise InvalidArgumentException(f"Invalid data format: {kwargs.get('data_format', None)}")

if limit > CFG.maximum_page_size and UI_REFERER not in connexion.request.headers.get("referer", ""):
if limit > CFG.maximum_page_size and not UI_REFERER.search(connexion.request.headers.get("referer", "")):
raise InvalidArgumentException(f"Page limit of size: {limit} is too high, maximum is {CFG.maximum_page_size}")

return {
Expand Down

0 comments on commit abd185a

Please sign in to comment.