Commit 28abd2dc authored by Afonso Castanheta's avatar Afonso Castanheta
Browse files

Refactor user validation logic to fix fail-open pattern vulnerability (API Discover Service)

parent 13fdb5c9
Loading
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ from ..encoder import CustomJSONEncoder
from ..models.problem_details import ProblemDetails
from ..util import serialize_clean_camel_case
from .resources import Resource
from .responses import internal_server_error
from .responses import internal_server_error, not_found_error, forbidden_error


class ControlAccess(Resource):
@@ -20,11 +20,11 @@ class ControlAccess(Resource):
            my_query = {'id': api_invoker_id}
            cert_entry = cert_col.find_one(my_query)

            if cert_entry is not None:
            if cert_entry is None:
                return not_found_error(detail="Please provide an existing Network App ID", cause="Certificate not found for invoker")
            
            if cert_entry["cert_signature"] != cert_signature:
                    prob = ProblemDetails(title="Unauthorized", detail="User not authorized", cause="You are not the owner of this resource")
                    prob = serialize_clean_camel_case(prob)
                    return Response(json.dumps(prob, cls=CustomJSONEncoder), status=401, mimetype="application/json")
                return forbidden_error(detail="User not authorized", cause="You are not the owner of this resource")

        except Exception as e:
            exception = "An exception occurred in validate invoker"
+2 −2
Original line number Diff line number Diff line
@@ -86,8 +86,8 @@ Discover Published service APIs by not registered API Invoker
    Check Response Variable Type And Values    ${resp}    404    ProblemDetails
    ...    title=Not Found
    ...    status=404
    ...    detail=API Invoker does not exist
    ...    cause=API Invoker id not found
    ...    detail=Please provide an existing Network App ID
    ...    cause=Certificate not found for invoker

Discover Published service APIs by registered API Invoker with 1 result filtered
    [Tags]    capif_api_discover_service-4   smoke