Repository navigation
Description
Controllers in FOCA apps get their inputs in two ways:
- from Connexion's injected arguments: path, query and body parameters,
user,token_info; - from Flask:
request.json,request.path,request.url,request.script_root,request.content_length,request.form/files,request_ctx.connexion_context.
FOCA's own code does the same: claims in enforcement.get_current_claims, path and method in is_permitted, script_root in utils/urls.py, the request line in utils/logging.py.
The ASGI release drops Flask. A scratch comparison of Connexion 2.15.1 and 3.3.0 showed:
- Injected arguments behave the same on both (path, query with defaults,
body,user,token_info,**kwargs). - Header parameters are injected in neither.
connexion.requestis Flask's request on 2.x and a Starlette-based request on 3.x. The 3.x request has no.pathand no.script_root.connexion.contextis a proxy on 2.x and a module on 3.x.- Paths differ: Starlette's
scope["path"]includes the root path; Flask'srequest.pathdoesn't. Policies and owners are keyed by the path, so this is security-relevant.
So apps need one FOCA accessor that means the same on both, plus the rule to take everything else from injected arguments.
Do:
-
foca.context.current_request(), a read-only snapshot:method;path: below the root path, the same as Flask'srequest.pathtoday;root_path,url;headers: case-insensitive, read-only;content_length;client_address;route: the path template from the route table (refactor: check routes from specs, not url_map #632), pluspath_params.
It raises a clear error outside a request.
-
Claims:
foca.security.auth.current_token_info()andcurrent_claims(). The existingget_current_claims()uses them; they are empty when no token was validated. -
Switch FOCA's internals to these accessors: enforcement, ownership,
utils/urls.py,utils/logging.py. Read request bodies only via injected arguments. The access-control server'srequest.get_json()becomes abodyargument. -
Config:
get_config()/get_custom_config()are the only supported ways to read the config in apps.current_app.config.focaandget_app_config(flask_app)are deprecated (DeprecationWarningwhere FOCA can emit one). -
Responses: document
(body, status, headers)tuples andNoContentas the portable return values, instead offlask.Response,make_responseandsend_file. They are verified to give the same responses on Connexion 2 and 3. -
The 0.22.0 implementation reads from Flask and Connexion 2. Only its body changes in the ASGI release.
Acceptance criteria
-
current_request(),current_token_info()andcurrent_claims()are public, typed, documented, and tested with a root path, a base path and headers. -
foca/reads no request data fromflask.request,request_ctxorconnexion.requestoutside the accessor module. - Policies and owners match exactly as before (existing access-control and ownership tests pass unchanged).
- Docs ("Writing controllers"): inputs via injected arguments, everything else via the accessors, portable return values, config via
get_config().
Decided
- Names as proposed:
foca.context.current_request(),foca.security.auth.current_claims()andcurrent_token_info(). - The request accessor is required in 0.22 (not optional or deferred).
- Access control stays a resolver wrapper; this issue only changes where it reads the request from.
foca.context already exists with request_id() if the request ID issue is done first. Prepares #188.
Activity