Skip to content

Commit

Permalink
feat: add option to configure REST API server header limit (#5594)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored May 31, 2023
1 parent 951fda6 commit fb6a57a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type RestApiServerOpts = {
cors?: string;
address?: string;
bearerToken?: string;
headerLimit?: number;
bodyLimit?: number;
};

Expand Down Expand Up @@ -60,6 +61,7 @@ export class RestApiServer {
parseArrays: false,
}),
bodyLimit: opts.bodyLimit,
http: {maxHeaderSize: opts.headerLimit},
});

this.activeSockets = new HttpActiveSocketsTracker(server.server, metrics);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr
port: args["keymanager.port"],
cors: args["keymanager.cors"],
isAuthEnabled: args["keymanager.authEnabled"],
headerLimit: args["keymanager.headerLimit"],
bodyLimit: args["keymanager.bodyLimit"],
tokenDir: dbPath,
},
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type KeymanagerArgs = {
"keymanager.port"?: number;
"keymanager.address"?: string;
"keymanager.cors"?: string;
"keymanager.headerLimit"?: number;
"keymanager.bodyLimit"?: number;
};

Expand Down Expand Up @@ -110,6 +111,11 @@ export const keymanagerOptions: CliCommandOptions<KeymanagerArgs> = {
defaultDescription: keymanagerRestApiServerOptsDefault.cors,
group: "keymanager",
},
"keymanager.headerLimit": {
hidden: true,
type: "number",
description: "Defines the maximum length of request headers, in bytes, the server is allowed to accept",
},
"keymanager.bodyLimit": {
hidden: true,
type: "number",
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/options/beaconNodeOptions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ApiArgs = {
rest: boolean;
"rest.address": string;
"rest.port": number;
"rest.headerLimit": number;
"rest.bodyLimit": number;
};

Expand All @@ -22,6 +23,7 @@ export function parseArgs(args: ApiArgs): IBeaconNodeOptions["api"] {
enabled: args["rest"],
address: args["rest.address"],
port: args["rest.port"],
headerLimit: args["rest.headerLimit"],
bodyLimit: args["rest.bodyLimit"],
},
};
Expand Down Expand Up @@ -77,6 +79,11 @@ export const options: CliCommandOptions<ApiArgs> = {
defaultDescription: String(defaultOptions.api.rest.port),
group: "api",
},
"rest.headerLimit": {
hidden: true,
type: "number",
description: "Defines the maximum length of request headers, in bytes, the server is allowed to accept",
},
"rest.bodyLimit": {
hidden: true,
type: "number",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/test/unit/options/beaconNodeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("options / beaconNodeOptions", () => {
rest: true,
"rest.address": "127.0.0.1",
"rest.port": 7654,
"rest.headerLimit": 16384,
"rest.bodyLimit": 30e6,

"chain.blsVerifyAllMultiThread": true,
Expand Down Expand Up @@ -105,6 +106,7 @@ describe("options / beaconNodeOptions", () => {
enabled: true,
address: "127.0.0.1",
port: 7654,
headerLimit: 16384,
bodyLimit: 30e6,
},
},
Expand Down

0 comments on commit fb6a57a

Please sign in to comment.