Skip to content

Commit c1356fc

Browse files
committed
feat: depth limits
1 parent 268fcc6 commit c1356fc

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

indexer/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependencies": {
99
"@apollo/server": "^4.11.0",
1010
"@aws-sdk/client-s3": "^3.514.0",
11+
"@graphile/depth-limit": "^0.3.1",
1112
"@graphql-codegen/cli": "^5.0.2",
1213
"@graphql-codegen/typescript": "^4.0.9",
1314
"@graphql-codegen/typescript-resolvers": "^4.2.1",
@@ -23,7 +24,7 @@
2324
"cors": "^2.8.5",
2425
"dataloader": "^2.2.2",
2526
"express": "^4.18.2",
26-
"graphql": "^16.9.0",
27+
"graphql": "^16.10.0",
2728
"graphql-query-complexity": "^1.0.0",
2829
"graphql-scalars": "^1.23.0",
2930
"graphql-subscriptions": "^2.0.0",

indexer/src/kadena-server/server.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ import { dispatchInfoSchema } from '../jobs/publisher-job';
2626
import initCache from '../cache/init';
2727
import { getRequiredEnvString } from '../utils/helpers';
2828
import ipRangeCheck from 'ip-range-check';
29-
import {
30-
createComplexityRule,
31-
fieldExtensionsEstimator,
32-
getComplexity,
33-
simpleEstimator,
34-
} from 'graphql-query-complexity';
29+
import { fieldExtensionsEstimator, getComplexity, simpleEstimator } from 'graphql-query-complexity';
30+
import { depthLimit } from '@graphile/depth-limit';
3531

3632
// Maximum allowed complexity
3733
const MAX_COMPLEXITY = 100;
34+
const MAX_DEPTH = 5;
3835

3936
const typeDefs = readFileSync(join(__dirname, './config/schema.graphql'), 'utf-8');
4037

@@ -125,6 +122,17 @@ export async function useKadenaGraphqlServer() {
125122
typeDefs,
126123
resolvers,
127124
introspection: true,
125+
validationRules: [
126+
depthLimit({
127+
maxDepth: 7, // Reasonable depth for most queries
128+
maxListDepth: 5, // Prevent deeply nested array queries
129+
maxSelfReferentialDepth: 2, // Limit recursive queries
130+
maxIntrospectionDepth: 15, // Limit introspection query depth
131+
maxIntrospectionListDepth: 8, // Limit introspection array depth
132+
maxIntrospectionSelfReferentialDepth: 2,
133+
revealDetails: false, // Don't expose limits to clients
134+
}),
135+
],
128136
plugins: [
129137
validatePaginationParamsPlugin,
130138
ApolloServerPluginDrainHttpServer({ httpServer }),

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,11 @@
15251525
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f"
15261526
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==
15271527

1528+
"@graphile/depth-limit@^0.3.1":
1529+
version "0.3.1"
1530+
resolved "https://registry.yarnpkg.com/@graphile/depth-limit/-/depth-limit-0.3.1.tgz#b0872a3a1cd7ac99555a39f897442f9b366d95e5"
1531+
integrity sha512-3MwdOEScb7yZJnU/qM4sR7MEW7Nge8XxsvBmj33YamP+1e2st43M1VDYviPnOvqAPrIg2PJvvuNux+IId8sn0A==
1532+
15281533
"@graphile/[email protected]":
15291534
version "4.11.0"
15301535
resolved "https://registry.yarnpkg.com/@graphile/lru/-/lru-4.11.0.tgz#dd805ee083063488796ec0eac5a8b50b21c076f9"
@@ -5913,10 +5918,10 @@ graphql-ws@^5.14.0, graphql-ws@^5.16.0, graphql-ws@^5.6.2:
59135918
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38"
59145919
integrity sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==
59155920

5916-
graphql@^16.9.0:
5917-
version "16.9.0"
5918-
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.9.0.tgz#1c310e63f16a49ce1fbb230bd0a000e99f6f115f"
5919-
integrity sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==
5921+
graphql@^16.10.0:
5922+
version "16.10.0"
5923+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.10.0.tgz#24c01ae0af6b11ea87bf55694429198aaa8e220c"
5924+
integrity sha512-AjqGKbDGUFRKIRCP9tCKiIGHyriz2oHEbPIbEtcSLSs4YjReZOIPQQWek4+6hjw62H9QShXHyaGivGiYVLeYFQ==
59205925

59215926
h3@^1.10.2, h3@^1.11.1:
59225927
version "1.11.1"

0 commit comments

Comments
 (0)