You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
http: docs, HttpRequestParser values are unsafe for access checks on path parameters #775
HttpRequestParser merges path, header, body and query values, later ones replacing earlier ones, as its JSDoc says. Its JSDoc example reads teamId in an onController listener; an access check written that way can be bypassed with a query parameter of the same name. The docs could say so next to the example and show HttpPath for such checks.
import{App}from'@deepkit/app';import{http,HttpAccessDeniedError,HttpKernel,HttpModule,HttpPath,HttpRequest,HttpRequestParser,httpWorkflow}from'@deepkit/http';typeTeamRouteData={teamId: string};constteamsOfCurrentUser=['mine'];classTeamController{
@http.GET('/teams/:teamId')show(teamId: string){return'secrets of team '+teamId;}}// access check with the merged values of HttpRequestParser, as in its JSDoc exampleconstcheckWithParser=httpWorkflow.onController.listen(async(event,parser: HttpRequestParser<TeamRouteData>)=>{if(!teamsOfCurrentUser.includes((awaitparser()).teamId))thrownewHttpAccessDeniedError();});// the same check with HttpPathconstcheckWithPath=httpWorkflow.onController.listen(async(event,teamId: HttpPath<string>)=>{if(!teamsOfCurrentUser.includes(teamId))thrownewHttpAccessDeniedError();});for(constlistenerof[checkWithParser,checkWithPath]){constapp=newApp({controllers: [TeamController],imports: [newHttpModule()],listeners: [listener]});constresponse=awaitapp.get(HttpKernel).request(HttpRequest.GET('/teams/victim?teamId=mine'));console.log(response.statusCode,response.bodyString);}// with HttpRequestParser: 200 "secrets of team victim" (the check saw teamId 'mine' from the query)// with HttpPath: 403 {"message":"Access denied"}
Activity