From c871b5019ebaf1c57e7c9666b741cfa6a5393942 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 23 May 2024 09:40:16 -0500 Subject: Bug: Compute numeric timestamp for the claims. --- gn2/wqflask/oauth2/toplevel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/toplevel.py b/gn2/wqflask/oauth2/toplevel.py index 23965cc1..f0179250 100644 --- a/gn2/wqflask/oauth2/toplevel.py +++ b/gn2/wqflask/oauth2/toplevel.py @@ -47,7 +47,7 @@ def authorisation_code(): "iss": str(oauth2_clientid()), "sub": request.args["user_id"], "aud": urljoin(authserver_uri(), "auth/token"), - "exp": (issued + datetime.timedelta(minutes=5)), + "exp": (issued + datetime.timedelta(minutes=5)).timestamp(), "nbf": int(issued.timestamp()), "iat": int(issued.timestamp()), "jti": str(uuid.uuid4())}, -- cgit v1.2.3 From 111593d7e1685db33188eb03685210db6656c0c8 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 3 Jun 2024 16:10:01 -0500 Subject: Ensure endpoint returns a response. --- gn2/wqflask/oauth2/users.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/users.py b/gn2/wqflask/oauth2/users.py index 8a935170..ed88aaa4 100644 --- a/gn2/wqflask/oauth2/users.py +++ b/gn2/wqflask/oauth2/users.py @@ -84,7 +84,8 @@ def logout(): f"{the_session['masquerading']['name']} " f"({the_session['masquerading']['email']})", "alert-success") - return redirect("/") + + return redirect("/") @users.route("/register", methods=["GET", "POST"]) def register_user(): -- cgit v1.2.3 From 67df44ac2df9f05da22634f04eaaf29393710e9f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 4 Jun 2024 12:05:08 -0500 Subject: Provide client data used for user verification. --- gn2/wqflask/oauth2/users.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/users.py b/gn2/wqflask/oauth2/users.py index ed88aaa4..520a13c5 100644 --- a/gn2/wqflask/oauth2/users.py +++ b/gn2/wqflask/oauth2/users.py @@ -1,6 +1,6 @@ import requests from uuid import UUID -from urllib.parse import urljoin +from urllib.parse import urljoin, urlparse from authlib.integrations.base_client.errors import OAuthError from flask import ( @@ -11,10 +11,16 @@ from . import client from . import session from .ui import render_ui from .checks import require_oauth2 -from .client import (oauth2_get, oauth2_post, oauth2_client, - authserver_uri, user_logged_in) -from .request_utils import ( - user_details, request_error, process_error, with_flash_error) +from .client import (oauth2_get, + oauth2_post, + oauth2_client, + authserver_uri, + user_logged_in) +from .request_utils import (user_details, + request_error, + process_error, + with_flash_error, + authserver_authorise_uri) users = Blueprint("user", __name__) @@ -106,7 +112,10 @@ def register_user(): "user_name": form.get("user_name"), "email": form.get("email_address"), "password": form.get("password"), - "confirm_password": form.get("confirm_password")}) + "confirm_password": form.get("confirm_password"), + **dict( + item.split("=") for item in + urlparse(authserver_authorise_uri()).query.split("&"))}) results = response.json() if "error" in results: error_messages = tuple( -- cgit v1.2.3 From 2439a4a0af29a57adc55fec093e4231c7b320ff6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 5 Jun 2024 16:12:35 -0500 Subject: Build phenotype results template URI on backend Build the template URI on the backend to remove the need to remember to update the javascript if the URI changes in the future. --- gn2/wqflask/oauth2/data.py | 4 +++- gn2/wqflask/static/new/javascript/auth/search_phenotypes.js | 4 ++-- gn2/wqflask/templates/oauth2/data-list-phenotype.html | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/data.py b/gn2/wqflask/oauth2/data.py index 29d68be0..b7c7800c 100644 --- a/gn2/wqflask/oauth2/data.py +++ b/gn2/wqflask/oauth2/data.py @@ -70,7 +70,9 @@ def __search_phenotypes__(query, template, **kwargs): selected_traits=selected_traits, search_results=search_results, search_endpoint=urljoin( authserver_uri(), "auth/data/search"), - gn_server_url = authserver_uri(), + auth_server_url=authserver_uri(), + pheno_results_template=urljoin( + authserver_uri(), "auth/data/search/phenotype/"), results_endpoint=urljoin( authserver_uri(), f"auth/data/search/phenotype/{job_id}"), diff --git a/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js b/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js index 99ecb16e..e9ef2683 100644 --- a/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js +++ b/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js @@ -96,8 +96,8 @@ function display_search_results(data, textStatus, jqXHR) { * @param {UUID}: The job id to fetch data for */ function fetch_search_results(job_id, success, error=default_error_fn) { - host = $("#frm-search-traits").attr("data-gn-server-url"); - endpoint = host + "auth/data/search/phenotype/" + job_id + endpoint = $("#frm-search-traits").attr( + "data-pheno-results-template").replace("", job_id); $("#txt-search").prop("disabled", true); $.ajax( endpoint, diff --git a/gn2/wqflask/templates/oauth2/data-list-phenotype.html b/gn2/wqflask/templates/oauth2/data-list-phenotype.html index e5172c70..b23c16e2 100644 --- a/gn2/wqflask/templates/oauth2/data-list-phenotype.html +++ b/gn2/wqflask/templates/oauth2/data-list-phenotype.html @@ -113,7 +113,7 @@
+ data-pheno-results-template="{{pheno_results_template}}"> {%if dataset_type == "mrna"%} mRNA: Search {%else%} -- cgit v1.2.3 From 16b9ccc56a99f1290825c36b3788590a585920a6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 5 Jun 2024 16:37:12 -0500 Subject: Build search URI endpoint on server rather than on JS To help with maintenance, build the search URI on the server rather than in the javascript. --- gn2/wqflask/oauth2/data.py | 2 +- gn2/wqflask/static/new/javascript/auth/search_phenotypes.js | 2 +- gn2/wqflask/templates/oauth2/data-list-phenotype.html | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/data.py b/gn2/wqflask/oauth2/data.py index b7c7800c..767de1a3 100644 --- a/gn2/wqflask/oauth2/data.py +++ b/gn2/wqflask/oauth2/data.py @@ -69,7 +69,7 @@ def __search_phenotypes__(query, template, **kwargs): template, traits=[], per_page=per_page, query=query, selected_traits=selected_traits, search_results=search_results, search_endpoint=urljoin( - authserver_uri(), "auth/data/search"), + request.host_url, "oauth2/data/phenotype/search"), auth_server_url=authserver_uri(), pheno_results_template=urljoin( authserver_uri(), "auth/data/search/phenotype/"), diff --git a/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js b/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js index e9ef2683..8689af75 100644 --- a/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js +++ b/gn2/wqflask/static/new/javascript/auth/search_phenotypes.js @@ -119,7 +119,7 @@ function search_phenotypes() { per_page = document.getElementById("txt-per-page").value search_table = new TableDataSource( "#tbl-phenotypes", "data-traits", search_checkbox); - endpoint = "/auth/data/phenotype/search" + endpoint = endpoint = $("#frm-search-traits").attr("data-search-endpoint"); $.ajax( endpoint, { diff --git a/gn2/wqflask/templates/oauth2/data-list-phenotype.html b/gn2/wqflask/templates/oauth2/data-list-phenotype.html index b23c16e2..d355f3f9 100644 --- a/gn2/wqflask/templates/oauth2/data-list-phenotype.html +++ b/gn2/wqflask/templates/oauth2/data-list-phenotype.html @@ -113,6 +113,7 @@ {%if dataset_type == "mrna"%} mRNA: Search -- cgit v1.2.3 From b22d5baffb236c522ff8469f3495b63912201094 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 5 Jun 2024 16:38:21 -0500 Subject: Bug: Add missing data to search query. --- gn2/wqflask/oauth2/data.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/data.py b/gn2/wqflask/oauth2/data.py index 767de1a3..16e5f60c 100644 --- a/gn2/wqflask/oauth2/data.py +++ b/gn2/wqflask/oauth2/data.py @@ -124,6 +124,7 @@ def json_search_mrna() -> Response: @data.route("/phenotype/search", methods=["POST"]) def json_search_phenotypes() -> Response: """Search for phenotypes.""" + from gn2.utility.tools import GN_SERVER_URL form = request.json def __handle_error__(err): error = process_error(err) @@ -138,6 +139,7 @@ def json_search_phenotypes() -> Response: "per_page": int(form.get("per_page", 50)), "page": int(form.get("page", 1)), "auth_server_uri": authserver_uri(), + "gn3_server_uri": GN_SERVER_URL, "selected_traits": form.get("selected_traits", []) }).either(__handle_error__, jsonify) -- cgit v1.2.3 From 503795f16fbed1b5e6ea7ecffeb1a25cf3548d8e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 6 Jun 2024 10:10:38 -0500 Subject: Deactivate the "create_role" function The `create_role` function could lead to privilege escalation. This commit deactivates it completely to prevent the chance of that happening. --- gn2/wqflask/oauth2/roles.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/roles.py b/gn2/wqflask/oauth2/roles.py index 2fe35f9b..ee75475e 100644 --- a/gn2/wqflask/oauth2/roles.py +++ b/gn2/wqflask/oauth2/roles.py @@ -93,7 +93,12 @@ def create_role(): def __create_success__(*args): flash("Role created successfully.", "alert-success") return redirect(url_for("oauth2.role.user_roles")) - return oauth2_post( - "auth/group/role/create",data={ - "role_name": role_name, "privileges[]": privileges}).either( - __create_error__,__create_success__) + + raise DeprecationWarning( + f"The `{__name__}.create_role(…)` function, as is currently, can " + "lead to unbounded privilege escalation. See " + "https://issues.genenetwork.org/issues/gn-auth/problems-with-roles") + # return oauth2_post( + # "auth/group/role/create",data={ + # "role_name": role_name, "privileges[]": privileges}).either( + # __create_error__,__create_success__) -- cgit v1.2.3 From e4fc0eb4ed80931bbd36f3777b06d9343a2008d0 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 6 Jun 2024 10:14:02 -0500 Subject: Remove the "Roles" page. --- gn2/wqflask/oauth2/roles.py | 25 ------------------------- gn2/wqflask/templates/oauth2/profile_nav.html | 7 ------- 2 files changed, 32 deletions(-) (limited to 'gn2/wqflask/oauth2') diff --git a/gn2/wqflask/oauth2/roles.py b/gn2/wqflask/oauth2/roles.py index ee75475e..b0f990c7 100644 --- a/gn2/wqflask/oauth2/roles.py +++ b/gn2/wqflask/oauth2/roles.py @@ -10,31 +10,6 @@ from .request_utils import request_error, process_error roles = Blueprint("role", __name__) -@roles.route("/user", methods=["GET"]) -@require_oauth2 -def user_roles(): - def __grerror__(roles, user_privileges, error): - return render_ui( - "oauth2/list_roles.html", roles=roles, - user_privileges=user_privileges, - group_roles_error=process_error(error)) - - def __grsuccess__(roles, user_privileges, group_roles): - return render_ui( - "oauth2/list_roles.html", roles=roles, - user_privileges=user_privileges, group_roles=group_roles) - - def __role_success__(roles): - uprivs = tuple( - privilege["privilege_id"] for role in roles - for privilege in role["privileges"]) - return oauth2_get("auth/group/roles").either( - lambda err: __grerror__(roles, uprivs, err), - lambda groles: __grsuccess__(roles, uprivs, groles)) - - return oauth2_get("auth/system/roles").either( - request_error, __role_success__) - @roles.route("/role/", methods=["GET"]) @require_oauth2 def role(role_id: uuid.UUID): diff --git a/gn2/wqflask/templates/oauth2/profile_nav.html b/gn2/wqflask/templates/oauth2/profile_nav.html index aa752905..c79bccbc 100644 --- a/gn2/wqflask/templates/oauth2/profile_nav.html +++ b/gn2/wqflask/templates/oauth2/profile_nav.html @@ -16,13 +16,6 @@ Group - -