fix: use whitelist approach in cleanWorkflowForUpdate to prevent API errors#927
Open
manato-tajiri wants to merge 1 commit into
Open
Conversation
Author
|
Note: The current npm version (2.63.2) already has a whitelist approach but is missing and . This PR adds those missing properties to the whitelist. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates workflow update sanitization to prevent n8n Cloud API rejections caused by unexpected/instance-specific workflow properties being included in update payloads.
Changes:
- Switch
cleanWorkflowForUpdatefrom a blacklist/rest-spread approach to a strict whitelist of accepted workflow properties. - Update unit tests to reflect that
activeandtagsare now preserved for updates. - Bump the lockfile version field to
2.28.3.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/services/n8n-validation.ts |
Implements a whitelist-based workflow cleaner for update requests to avoid “additional properties” API errors. |
tests/unit/services/n8n-validation.test.ts |
Adjusts expectations for update cleaning to keep active and tags. |
package-lock.json |
Updates lockfile package version metadata to 2.28.3. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
330
to
333
| const cleaned = cleanWorkflowForUpdate(workflow); | ||
|
|
||
| // Should remove all these fields | ||
| // With whitelist approach, only name, nodes, connections, settings, active, tags are kept | ||
| expect(cleaned).not.toHaveProperty('id'); |
Comment on lines
+346
to
349
| // active and tags ARE whitelisted, so they should be present | ||
| expect(cleaned).toHaveProperty('active'); | ||
| expect(cleaned).toHaveProperty('tags'); // Should keep name and filter settings to safe properties | ||
| expect(cleaned.name).toBe('Updated Workflow'); |
Comment on lines
+138
to
+143
| const whitelistedProperties = ['name', 'nodes', 'connections', 'settings', 'active', 'tags'] as const; | ||
| for (const key of whitelistedProperties) { | ||
| if (key in workflow) { | ||
| (cleanedWorkflow as any)[key] = (workflow as any)[key]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The function used a blacklist approach that destructured out specific known properties but passed through any unknown properties via the rest spread. n8n cloud instances return properties like , , , , , that were not in the blacklist, causing the n8n API to reject requests with "additional properties" errors.
This affects all operations (updateName, updateNode, addNode, addConnection, removeConnection).
Fix
Changed from a blacklist approach to a whitelist approach. The function now only includes the 6 properties the n8n API accepts in :
Testing
Fixes the "additional properties" error on all partial update operations for n8n cloud instances.