Skip to content

http: docs, HttpRequestParser values are unsafe for access checks on path parameters #775

Open

Description

@lionelhorn

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';

type TeamRouteData = { teamId: string };
const teamsOfCurrentUser = ['mine'];

class TeamController {
    @http.GET('/teams/:teamId')
    show(teamId: string) {
        return 'secrets of team ' + teamId;
    }
}

// access check with the merged values of HttpRequestParser, as in its JSDoc example
const checkWithParser = httpWorkflow.onController.listen(async (event, parser: HttpRequestParser<TeamRouteData>) => {
    if (!teamsOfCurrentUser.includes((await parser()).teamId)) throw new HttpAccessDeniedError();
});

// the same check with HttpPath
const checkWithPath = httpWorkflow.onController.listen(async (event, teamId: HttpPath<string>) => {
    if (!teamsOfCurrentUser.includes(teamId)) throw new HttpAccessDeniedError();
});

for (const listener of [checkWithParser, checkWithPath]) {
    const app = new App({ controllers: [TeamController], imports: [new HttpModule()], listeners: [listener] });
    const response = await app.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"}

Master 0bb9fba, Node 26.13.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions