From 6475cc631ebc9a8e96c8282522093470fd9cd515 Mon Sep 17 00:00:00 2001 From: pbakker Date: Tue, 19 Nov 2024 11:06:49 -0800 Subject: [PATCH] Set the max character setting to Int.MAX. We don't have to worry about DDOS for codegen. --- .../kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt index cc7656eb..694a7fcc 100644 --- a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt +++ b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGen.kt @@ -62,6 +62,7 @@ class CodeGen(private val config: CodeGenConfig) { companion object { private const val SDL_MAX_ALLOWED_SCHEMA_TOKENS: Int = Int.MAX_VALUE + private const val SDL_MAX_CHARACTERS: Int = Int.MAX_VALUE private val logger: Logger = LoggerFactory.getLogger(CodeGen::class.java) } @@ -112,7 +113,10 @@ class CodeGen(private val config: CodeGenConfig) { */ private fun buildDocument(): Document { val options = ParserOptions.getDefaultParserOptions().transform { builder -> - builder.maxTokens(SDL_MAX_ALLOWED_SCHEMA_TOKENS).maxWhitespaceTokens(SDL_MAX_ALLOWED_SCHEMA_TOKENS) + builder + .maxTokens(SDL_MAX_ALLOWED_SCHEMA_TOKENS) + .maxWhitespaceTokens(SDL_MAX_ALLOWED_SCHEMA_TOKENS) + .maxCharacters(SDL_MAX_CHARACTERS) } val parser = Parser() @@ -139,7 +143,7 @@ class CodeGen(private val config: CodeGenConfig) { parser.parseDocument(parserEnv) } catch (exception: InvalidSyntaxException) { // check if the schema is empty - if (exception.sourcePreview == null || exception.sourcePreview.isBlank()) { + if (exception.sourcePreview != null && exception.sourcePreview.isBlank()) { logger.warn("Schema is empty") // return an empty document return Document.newDocument().build()