-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: add extra validation for vercel sync #6094
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
maidul98
wants to merge
1
commit into
main
Choose a base branch
from
vercel-sync-add-validation
base: main
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.
+24
−0
Open
Changes from all commits
Commits
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 When
targetEnvironmentsis empty andsensitiveistrue, the new Team-scope checkconfig.targetEnvironments.every(...)fires vacuously ([].every(fn) === truein JavaScript), producing the misleading error "not supported for development environments" alongside the correct "At least one environment is required" error. Fix: addconfig.targetEnvironments.length > 0 &&before the.every()call in both the backend schema (vercel-sync-schemas.tsline 54) and the frontend schema (vercel-sync-destination-schema.tsline 53).Extended reasoning...
What the bug is and how it manifests
Both the backend (
backend/src/services/secret-sync/vercel/vercel-sync-schemas.ts, lines 54–63) and frontend (frontend/src/components/secret-syncs/forms/schemas/vercel-sync-destination-schema.ts, lines 53–63) Vercel sync schemas have a newsuperRefinecheck that fires whenscope === Teamand every selected environment isDevelopment. The intent is to prevent marking a Team-scoped sync as sensitive when it only targets dev environments. However, the guard omits a length check, making it susceptible to JavaScript's vacuous truth behavior.The specific code path that triggers it
When
targetEnvironmentsis an empty array[],[].every(fn)unconditionally returnstruein JavaScript (vacuous truth — there are no elements that violate the predicate). This means the entire condition evaluates totruewheneverscope === Team,sensitive === true, andtargetEnvironmentsis empty.Why existing code doesn't prevent it
In Zod v3,
superRefineruns even after inner field refinements (such as.min(1)) have already added validation errors. The.min(1)constraint ontargetEnvironmentsis a refinement, not a type narrowing — it adds an issue but does not abort parsing. The empty array[]still satisfies the TypeScript typeVercelEnvironmentType[], so the discriminated union branch matches and the value is passed tosuperRefine.Impact
A user who submits the form (or makes a direct API call) with
scope=Team,targetEnvironments=[], andsensitive=truewill see two error messages simultaneously:The second message actively misdirects the user.
Step-by-step proof
scope = Team, checkssensitive = true, and leavestargetEnvironmentsas[](empty).scope === Teammatches the second branch..min(1)refinement ontargetEnvironmentsadds:"At least one environment is required".superRefineis called with{ scope: 'team', targetEnvironments: [], sensitive: true, ... }.!config.sensitiveisfalse, so the early return is skipped.config.scope === VercelSyncScope.Team→true.[].every(env => env === VercelEnvironmentType.Development)→true(vacuous truth).ctx.addIssue()fires, adding the misleading message.How to fix it
Add a length guard before the
.every()call in both files:This ensures the sensitive/dev-environment error only fires when at least one environment has actually been selected and all of them are
Development.