fix(workflows): harden workflow API auth routes#3559
fix(workflows): harden workflow API auth routes#3559PlaneInABottle wants to merge 24 commits intosimstudioai:stagingfrom
Conversation
PR SummaryMedium Risk Overview Improves audit attribution for API-key callers by propagating Adds targeted Vitest coverage across middleware and workflow endpoints (deploy, deployed state, deployments list/version activation/revert, status, lifecycle, async execute error handling) and updates docs to clarify lifecycle/deployment endpoints can be called programmatically with session auth or API keys where supported. Written by Cursor Bugbot for commit 6f2e6eb. This will update automatically on new commits. Configure here. |
|
Someone is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR hardens the workflow API auth layer by introducing a shared Key observations:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Request] --> B{Auth Type?}
B -->|Bearer JWT| C[verifyInternalToken\ndeployed/route only]
C -->|valid| D[Skip validateWorkflowAccess\nload deployed state directly]
C -->|invalid| E[validateWorkflowAccess]
B -->|Session / API Key / Internal Secret| E
E --> F[getWorkflowById]
F -->|not found| G[404 Workflow not found]
F -->|found, no workspaceId| H[403 Personal workflow deprecated]
F -->|requireDeployment: false| I[checkHybridAuth]
I -->|fail / no userId| J[401 Unauthorized]
I -->|success + userId| K[authorizeWorkflowByWorkspacePermission\naction: read / write / admin]
K -->|denied| L[403 / 404 Access denied]
K -->|allowed| M[Return workflow + auth]
F -->|requireDeployment: true| N{isDeployed?}
N -->|false| O[403 Workflow not deployed]
N -->|true| P{Internal Secret header?}
P -->|valid + allowInternalSecret| Q[Return workflow — no userId]
P -->|missing / invalid| R[Check X-Api-Key header]
R -->|missing| S[401 API key required]
R -->|present| T[authenticateApiKeyFromHeader\nworkspace or personal]
T -->|fail| U[401 Invalid API key]
T -->|success| V[updateApiKeyLastUsed\nReturn workflow]
M --> W[Route handler\nDELETE / PUT / POST / PATCH / GET]
V --> W
Q --> W
|
888a246 to
aab58cb
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@PlaneInABottle this PR might have to wait till our v0.6 release. Lot of auth changes there that might overwrite this potentially |
|
@PlaneInABottle can you rebase against staging |
Co-authored-by: GitHub Copilot <github-copilot[bot]@users.noreply.github.com>
Co-authored-by: GitHub Copilot <github-copilot[bot]@users.noreply.github.com>
Co-authored-by: GitHub Copilot <github-copilot[bot]@users.noreply.github.com>
Use the shared audit actor helper consistently so workflow deletion matches deploy behavior and remove the redundant deploy wrapper raised in review.
Call validateWorkflowAccess directly in workflow deployment lifecycle routes and clean up the related test helper formatting raised in review.
a264ee9 to
2c267c0
Compare
|
@icecrasher321 rebased |
|
@PlaneInABottle looks like one more conflict sorry. One thing -- I see you changed routes like revert to share the same auth as deploy. That's a bit confusing to me, since those are currently only UI actions. Shouldn't we keep more deliberate / as narrowly scoped auth as possible. We don't intend things like revert to be API key accessible. |
@icecrasher321 I did it for to control sim with ai. I am using sim generally with ai, not with ui at all. Only to check the workflows' blocks, orders etc. I mean it is of course a design choice. I could remove it but I do think sim would be better with it. You could also advertise sim with this feature :D . For example I do believe also it could attract not only developers because it is opensource, but it could also attract vibecoders against n8n. |
|
@PlaneInABottle That's interesting, this makes sense. I'm not against making these publicly hittable endpoints. Can you fix the merge conflict and also add this to the docs so it's not a hidden feature. Only add it to the english docs it'll auto translate. |
ce2ed79 to
1f61db8
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Summary
What changed
stagingname/emailinto deploy, activate, and revert audit recordsValidation