Skip to content

Conversation

@MilanKomsa
Copy link

No description provided.

}

// Validate against GS1 schema
const isValid = this.validateSchema(document);

Check failure

Code scanning / CodeQL

Resources exhaustion from deep object traversal High

Denial of service caused by processing
user input
with
allErrors: true
.

Copilot Autofix

AI 4 days ago

In general, the fix is to avoid using allErrors: true when validating user-controlled input in production. Instead, only enable allErrors conditionally (e.g., based on an environment variable or a debug flag) so production validates only until the first error and does not allocate unbounded error arrays.

The best fix here is to change the Ajv instantiation in EpcisValidationService to make allErrors conditional on an environment variable (for example EPCIS_DEBUG), mirroring the recommended pattern from the background section. This keeps current functionality for debugging (developers can still see all validation errors when they explicitly enable debug mode), but prevents the denial-of-service risk in normal operation. No other logic needs to change, because Ajv’s errors array is still populated when validation fails; it will just contain fewer entries in non-debug mode.

Concretely, in packages/plugin-epcis/src/services/EPCISValidationService.ts, update the constructor where new Ajv is called: replace allErrors: true with allErrors: process.env["EPCIS_DEBUG"] === "true". This is the only code change needed. No changes are required in packages/plugin-epcis/src/index.ts, and no new imports or helper methods are necessary.

Suggested changeset 1
packages/plugin-epcis/src/services/EPCISValidationService.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/plugin-epcis/src/services/EPCISValidationService.ts b/packages/plugin-epcis/src/services/EPCISValidationService.ts
--- a/packages/plugin-epcis/src/services/EPCISValidationService.ts
+++ b/packages/plugin-epcis/src/services/EPCISValidationService.ts
@@ -9,7 +9,7 @@
 
   constructor() {
     this.ajv = new Ajv({
-      allErrors: true,
+      allErrors: process.env["EPCIS_DEBUG"] === "true",
       strict: false,
       validateFormats: true,
     });
EOF
@@ -9,7 +9,7 @@

constructor() {
this.ajv = new Ajv({
allErrors: true,
allErrors: process.env["EPCIS_DEBUG"] === "true",
strict: false,
validateFormats: true,
});
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

@Lexpeartha Lexpeartha left a comment

Choose a reason for hiding this comment

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

Please also document new .env variable and add it to env.d.ts

@MilanKomsa
Copy link
Author

Please also document new .env variable and add it to env.d.ts
What new .env variable?

@MilanKomsa MilanKomsa requested a review from Lexpeartha January 16, 2026 14:43
@MilanKomsa MilanKomsa dismissed Lexpeartha’s stale review January 16, 2026 14:44

there is no .env variable used in code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants