-
Notifications
You must be signed in to change notification settings - Fork 213
n8n REST API exposed detector #806
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
Open
YuriyPobezhymov
wants to merge
5
commits into
google:master
Choose a base branch
from
YuriyPobezhymov:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10d83de
n8n rest api exposed detector
YuriyPobezhymov 4bbe9ed
n8n rest api exposed detector updated
YuriyPobezhymov f4d9c6c
recommendation improvement
YuriyPobezhymov 5ec5068
Update templated/templateddetector/plugins/exposedui/N8N_ExposedRestA…
YuriyPobezhymov 6c26006
Update templated/templateddetector/plugins/exposedui/N8N_ExposedRestA…
YuriyPobezhymov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
templated/templateddetector/plugins/exposedui/N8N_ExposedRestApi.textproto
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # proto-file: proto/templated_plugin.proto | ||
| # proto-message: TemplatedPlugin | ||
|
|
||
| ############### | ||
| # PLUGIN INFO # | ||
| ############### | ||
|
|
||
| info: { | ||
| type: VULN_DETECTION | ||
| name: "N8N_ExposedRestApi" | ||
| author: "yuradoc (yuradoc.research@gmail.com)" | ||
| version: "1.0" | ||
| } | ||
|
|
||
| finding: { | ||
| main_id: { | ||
| publisher: "GOOGLE" | ||
| value: "N8N_EXPOSED_REST_API" | ||
| } | ||
| title: "Exposed n8n REST API" | ||
| description: | ||
| "The n8n automation platform instance exposes its REST API without proper " | ||
| "authentication, allowing unauthenticated access to workflow management " | ||
| "functionality. This may enable attackers to enumerate, modify, and execute " | ||
| "workflows, including those containing built-in command execution nodes, " | ||
| "potentially leading to remote code execution. Exposure conditions vary " | ||
| "across n8n versions. Early releases without user management did not " | ||
| "consistently protect REST endpoints, and available authentication mechanisms " | ||
| "(e.g., JWT or basic auth) may not fully cover all /rest/* routes. In later " | ||
| "0.x versions, authentication behavior may be inconsistent—for example, " | ||
| "instances without an initialized owner account or with ineffective " | ||
| "configuration flags may allow unauthenticated access to /rest/* endpoints." | ||
| recommendation: | ||
| "Upgrade the n8n instance to a recent supported version where authentication " | ||
| "is consistently enforced by default. Older 0.x versions may not reliably " | ||
| "protect REST API endpoints. Additionally, ensure authentication is properly " | ||
| "configured and that the instance is not exposed to untrusted networks. Verify " | ||
| "that all REST API endpoints are protected, especially in partially initialized " | ||
| "deployments. Refer to https://docs.n8n.io/hosting/securing/overview/ for guidance." | ||
| severity: CRITICAL | ||
| } | ||
|
|
||
| ########### | ||
| # ACTIONS # | ||
| ########### | ||
|
|
||
| actions: { | ||
| name: "n8n_vuln_fingerprint" | ||
| http_request: { | ||
| method: GET | ||
| uri: "/rest/settings" | ||
| response: { | ||
| http_status: 200 | ||
| expect_all: { | ||
| conditions: [ | ||
| { body: {} contains: '"urlBaseWebhook"' }, | ||
| { body: {} contains: '"versionCli":"0.' } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Gets the cookie if available, still passes this step if not available. | ||
| actions: { | ||
| name: "n8n_retrieve_auth_cookie" | ||
| http_request: { | ||
| method: GET | ||
| uri: "/rest/login" | ||
| response: { | ||
| extract_any: { | ||
| patterns: [ | ||
| { | ||
| from_header: { name: "Set-Cookie" } | ||
| regexp: "(n8n-auth=[^;]+)" | ||
| variable_name: "n8n_auth_token" | ||
| }, | ||
| { | ||
| from_body: {} | ||
| regexp: "()" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
YuriyPobezhymov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Gets workflows, sending the previous cookie if it was available. | ||
| actions: { | ||
| name: "n8n_retrieve_existing_flows" | ||
| http_request: { | ||
| method: GET | ||
| uri: "/rest/workflows" | ||
| headers: [ | ||
| { name: "Cookie" value: "{{ n8n_auth_token }}" } | ||
| ] | ||
| response: { | ||
| http_status: 200 | ||
| expect_all: { | ||
| conditions: [ | ||
| { body: {} contains: '"data":[' } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ############# | ||
| # WORKFLOWS # | ||
| ############# | ||
|
|
||
| workflows: { | ||
| actions: [ | ||
| "n8n_vuln_fingerprint", | ||
| "n8n_retrieve_auth_cookie", | ||
| "n8n_retrieve_existing_flows" | ||
| ] | ||
| } | ||
114 changes: 114 additions & 0 deletions
114
templated/templateddetector/plugins/exposedui/N8N_ExposedRestApi_test.textproto
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # proto-file: proto/templated_plugin_tests.proto | ||
| # proto-message: TemplatedPluginTests | ||
|
|
||
| config: { | ||
| tested_plugin: "N8N_ExposedRestApi" | ||
| } | ||
|
|
||
| tests: { | ||
| name: "whenVulnerable_noOwner_returnsTrue" | ||
| expect_vulnerability: true | ||
|
|
||
| mock_http_server: { | ||
| mock_responses: [ | ||
| { | ||
| uri: "/rest/settings" | ||
| status: 200 | ||
| body_content: '{"data":{"urlBaseWebhook":"http://target:5678/","versionCli":"0.237.0",...}}' | ||
| }, | ||
| { | ||
| uri: "/rest/login" | ||
| status: 200 | ||
| headers: [ | ||
| { name: "Set-Cookie" value: "n8n-auth=jwt_token" } | ||
| ] | ||
| }, | ||
| { | ||
| uri: "/rest/workflows" | ||
| status: 200 | ||
| condition: { | ||
| headers: [ | ||
| { name: "Cookie" value: "n8n-auth=jwt_token" } | ||
| ] | ||
| } | ||
| body_content: '{"data":[{"id":"Q2cpznBmI6NCfeBF","name":"Vulnerable Workflow",...},...]}' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| tests: { | ||
| name: "whenVulnerable_noUserManagement_returnsTrue" | ||
| expect_vulnerability: true | ||
|
|
||
| mock_http_server: { | ||
| mock_responses: [ | ||
| { | ||
| uri: "/rest/settings" | ||
| status: 200 | ||
| body_content: '{"data":{"urlBaseWebhook":"http://target:5678/","versionCli":"0.54.0",...}}' | ||
| }, | ||
| { | ||
| uri: "/rest/login" | ||
| status: 404 | ||
| }, | ||
| { | ||
| uri: "/rest/workflows" | ||
| status: 200 | ||
| body_content: '{"data":[{"id":"1","name":"Legacy Workflow",...},...]}' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| tests: { | ||
| name: "whenNotVulnerable_restProtected_returnsFalse" | ||
| expect_vulnerability: false | ||
|
|
||
| mock_http_server: { | ||
| mock_responses: [ | ||
| { | ||
| uri: "/rest/settings" | ||
| status: 200 | ||
| body_content: '{"data":{"urlBaseWebhook":"http://target:5678/","versionCli":"0.237.0",...}}' | ||
| }, | ||
| { | ||
| uri: "/rest/login" | ||
| status: 401 | ||
| }, | ||
| { | ||
| uri: "/rest/workflows" | ||
| status: 401 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| tests: { | ||
| name: "whenNotVulnerable_n8nModern_returnsFalse" | ||
| expect_vulnerability: false | ||
|
|
||
| mock_http_server: { | ||
| mock_responses: [ | ||
| { | ||
| uri: "/rest/settings" | ||
| status: 200 | ||
| body_content: '{"data":{"instanceId":"...","versionCli":"1.123.21"}}' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| tests: { | ||
| name: "whenNotN8n_returnsFalse" | ||
| expect_vulnerability: false | ||
|
|
||
| mock_http_server: { | ||
| mock_responses: [ | ||
| { | ||
| uri: "/rest/settings" | ||
| status: 404 | ||
| } | ||
| ] | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.