Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array query string parsing #5268

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
"@lodestar/utils": "^1.5.1",
"cross-fetch": "^3.1.4",
"eventsource": "^2.0.2",
"qs": "^6.10.1"
"qs": "^6.11.1"
},
"devDependencies": {
"@types/eventsource": "^1.1.5",
"@types/qs": "^6.9.6",
"@types/qs": "^6.9.7",
"ajv": "^8.11.0",
"fastify": "3.29.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import querystring from "querystring";
import qs from "qs";
import fastify, {FastifyInstance} from "fastify";
import Sinon from "sinon";
import {mapValues} from "@lodestar/utils";
Expand All @@ -10,7 +10,7 @@ export function getTestServer(): {baseUrl: string; server: FastifyInstance} {

const server = fastify({
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: querystring.parse,
querystringParser: (str) => qs.parse(str, {comma: true}),
});

server.addHook("onError", (request, reply, error, done) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"libp2p": "0.42.2",
"prom-client": "^14.1.0",
"prometheus-gc-stats": "^0.6.3",
"qs": "^6.11.1",
"snappyjs": "^0.7.0",
"stream-to-it": "^0.2.0",
"strict-event-emitter-types": "^2.0.0",
Expand All @@ -164,6 +165,7 @@
"@types/eventsource": "^1.1.5",
"@types/leveldown": "^4.0.2",
"@types/prometheus-gc-stats": "^0.6.1",
"@types/qs": "^6.9.7",
"@types/supertest": "^2.0.12",
"@types/tmp": "^0.2.0",
"@types/varint": "^6.0.0",
Expand Down
12 changes: 10 additions & 2 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import querystring from "querystring";
import qs from "qs";
import fastify, {FastifyError, FastifyInstance} from "fastify";
import fastifyCors from "fastify-cors";
import bearerAuthPlugin from "fastify-bearer-auth";
Expand Down Expand Up @@ -43,7 +43,15 @@ export class RestApiServer {
const server = fastify({
logger: false,
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: querystring.parse,
querystringParser: (str) =>
qs.parse(str, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// defaults to 20 but Beacon API spec allows max items of 30
arrayLimit: 30,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beacon API spec defines 30 as maxItems for some values, e.g. getStateValidators - id query, see spec value

// array as comma-separated values must be supported to be OpenAPI spec compliant
comma: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

koa openapi req/res validator uses this library as well and sets comma: true, this is required to be OpenAPI spec compliant, see Parameter Serialization

// default limit of 1000 seems unnecessarily high, let's reduce it a bit
parameterLimit: 100,
}),
bodyLimit: opts.bodyLimit,
});

Expand Down
2 changes: 2 additions & 0 deletions packages/light-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
},
"devDependencies": {
"@chainsafe/as-sha256": "^0.3.1",
"@types/qs": "^6.9.7",
nflaig marked this conversation as resolved.
Show resolved Hide resolved
"qs": "^6.11.1",
"uint8arrays": "^4.0.2"
},
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions packages/light-client/test/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import querystring from "querystring";
import qs from "qs";
import fastify, {FastifyInstance} from "fastify";
import fastifyCors from "fastify-cors";
import {Api, ServerApi} from "@lodestar/api";
Expand All @@ -18,7 +18,7 @@ export async function startServer(
const server = fastify({
logger: false,
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: querystring.parse,
querystringParser: (str) => qs.parse(str, {comma: true}),
});

registerRoutes(server, config, api, ["lightclient", "proof", "events"]);
Expand Down
17 changes: 12 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3406,10 +3406,10 @@
resolved "https://registry.npmjs.org/@types/prometheus-gc-stats/-/prometheus-gc-stats-0.6.1.tgz"
integrity sha512-tSj7MRNgEJCSqVRgPL4WIIcslZChgL6gVwnVFsAj2nTx0RdcG7iSpWm+0fkAKEe7e/YQ08TZH4wQWxpFODYqJw==

"@types/qs@^6.9.6":
version "6.9.6"
resolved "https://registry.npmjs.org/@types/qs/-/qs-6.9.6.tgz"
integrity sha512-0/HnwIfW4ki2D8L8c9GVcG5I72s9jP5GSLVF0VIXDW00kmIpA6O33G7a8n59Tmh7Nz0WUC3rSb7PTY/sdW2JzA==
"@types/qs@^6.9.7":
version "6.9.7"
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb"
nflaig marked this conversation as resolved.
Show resolved Hide resolved
integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==

"@types/readable-stream@*":
version "2.3.11"
Expand Down Expand Up @@ -10992,13 +10992,20 @@ qs@6.9.3:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.3.tgz#bfadcd296c2d549f1dffa560619132c977f5008e"
integrity sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==

qs@^6.10.1, qs@^6.10.3:
qs@^6.10.3:
version "6.11.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a"
integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==
dependencies:
side-channel "^1.0.4"

qs@^6.11.1:
version "6.11.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.1.tgz#6c29dff97f0c0060765911ba65cbc9764186109f"
integrity sha512-0wsrzgTz/kAVIeuxSjnpGC56rzYtr6JT/2BwEvMaPhFIoYa1aGO8LbzuU1R0uUYQkLpWBTOj0l/CLAJB64J6nQ==
dependencies:
side-channel "^1.0.4"

querystring-es3@^0.2.0:
version "0.2.1"
resolved "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz"
Expand Down