access-protected-vercel-deployment
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAccess Protected Vercel Deployments
访问受保护的Vercel部署
Use the caller's existing Vercel authentication. Do not disable Deployment Protection or ask for a long-lived bypass secret as the first solution.
使用调用者已有的Vercel身份验证信息。不要将禁用Deployment Protection或请求长期绕过密钥作为首选解决方案。
Choose the access path
选择访问路径
HTTP requests: use vercel curl
vercel curlHTTP请求:使用vercel curl
vercel curlFor response bodies, headers, health checks, and API calls, replace raw with (). It accepts native curl options and uses Vercel authentication to access protected preview and production deployments.
curlvercel curlvc curlbash
vc curl https://my-app.vercel.app/api/health
vc curl https://app.example.com/api/health
vc curl my-app.vercel.app/api/users -X POST \
-H "Content-Type: application/json" \
-d '{"name":"Ada"}'
vc curl /api/healthThe path-only form targets the linked project's production deployment. Pass a full URL when the exact deployment matters.
If authentication fails, check the local identity and project before changing protection settings:
bash
vc whoamiInspect to confirm the linked project and team. Run only when the directory is not linked or is linked to the wrong project. Run only when the CLI reports that no authenticated user is available.
.vercel/project.jsonvc linkvc login对于响应体、请求头、健康检查和API调用,将原生替换为(简称)。它支持原生curl选项,并通过Vercel身份验证访问受保护的预览和生产部署。
curlvercel curlvc curlbash
vc curl https://my-app.vercel.app/api/health
vc curl https://app.example.com/api/health
vc curl my-app.vercel.app/api/users -X POST \
-H "Content-Type: application/json" \
-d '{"name":"Ada"}'
vc curl /api/health仅传入路径的形式会指向已关联项目的生产部署。当需要指定具体部署时,请传入完整URL。
如果身份验证失败,请先检查本地身份信息和关联项目,再修改保护设置:
bash
vc whoami查看以确认关联的项目和团队。仅当目录未关联项目或关联了错误项目时,才运行。仅当CLI提示无已认证用户时,才运行。
.vercel/project.jsonvc linkvc loginBrowser automation: attach the development OIDC token as a header
浏览器自动化:添加开发环境OIDC令牌作为请求头
Browser requests must include the short-lived local token as a request header:
text
x-vercel-trusted-oidc-idp-token: <VERCEL_OIDC_TOKEN>Use a browser tool that supports origin-scoped request headers. With , inject development variables without printing or persisting the token:
agent-browserbash
vc env run -- sh -c \
'test -n "$VERCEL_OIDC_TOKEN" && agent-browser open "$1" --headers "{\"x-vercel-trusted-oidc-idp-token\":\"$VERCEL_OIDC_TOKEN\"}"' \
sh https://my-app.vercel.appThen continue the normal browser workflow in the same session. For Playwright or another browser driver, set the same header in the browser context's extra HTTP headers before the first navigation.
If the local CLI version does not provide the token through , refresh local development credentials with:
vc env runbash
vc env pull .env.local --yesLoad the file through the project's existing dotenv mechanism. Never print the token, paste its value into source code, or commit .
.env.localUse for Trusted Sources. Do not substitute ; that header carries an OIDC token into a Vercel Function and serves a different purpose.
x-vercel-trusted-oidc-idp-tokenx-vercel-oidc-token浏览器请求必须将短期本地令牌作为请求头传入:
text
x-vercel-trusted-oidc-idp-token: <VERCEL_OIDC_TOKEN>使用支持源范围请求头的浏览器工具。通过,无需打印或持久化令牌即可注入开发环境变量:
agent-browserbash
vc env run -- sh -c \
'test -n "$VERCEL_OIDC_TOKEN" && agent-browser open "$1" --headers "{\"x-vercel-trusted-oidc-idp-token\":\"$VERCEL_OIDC_TOKEN\"}"' \
sh https://my-app.vercel.app之后在同一会话中继续正常的浏览器工作流。对于Playwright或其他浏览器驱动,请在首次导航前,在浏览器上下文的额外HTTP请求头中设置相同的请求头。
如果本地CLI版本无法通过提供令牌,请通过以下命令刷新本地开发凭据:
vc env runbash
vc env pull .env.local --yes通过项目现有的dotenv机制加载该文件。切勿打印令牌、将其值粘贴到源代码中,或提交文件。
.env.local对于可信来源(Trusted Sources),请使用。不要替换为;该请求头用于将OIDC令牌传入Vercel Function,用途不同。
x-vercel-trusted-oidc-idp-tokenx-vercel-oidc-tokenTrusted Sources rules
可信来源规则
A local development token for a linked Vercel project can access that same project's Preview deployments by default. It does not automatically access protected Production deployments. For protected Production, the project's own Trusted Sources entry must allow → .
developmentproductionDo not ask the user to configure Trusted Sources for the normal same-project Preview case.
Configuration is needed when:
- the target is a protected Production deployment and the caller uses a local development token;
- the caller belongs to another Vercel project or team;
- the target project's self-access rules were customized; or
- the response is .
TRUSTED_SOURCES_ENVIRONMENT_MISMATCH
In the target project, open Settings → Deployment Protection → Trusted Sources. Add or edit the caller and allow the required → environment pair. A local token has the environment, so access to protected Production requires → .
fromtodevelopmentdevelopmentproductionTreat this as an access-control change: explain the exact rule required and obtain authorization before changing it. Do not broaden unrelated environment pairs.
已关联Vercel项目的本地开发令牌默认可以访问同一项目的预览部署,但不会自动访问受保护的生产部署。对于受保护的生产环境,项目自身的可信来源条目必须允许 → 的访问。
developmentproduction不要要求用户为常规的同项目预览场景配置可信来源。
以下情况需要进行配置:
- 目标是受保护的生产部署,且调用者使用本地开发令牌;
- 调用者属于另一个Vercel项目或团队;
- 目标项目的自访问规则已被自定义;
- 响应提示为。
TRUSTED_SOURCES_ENVIRONMENT_MISMATCH
在目标项目中,打开设置 → 部署保护 → 可信来源。添加或编辑调用者信息,并允许所需的 → 环境配对。本地令牌属于环境,因此访问受保护的生产环境需要配置 → 。
fromtodevelopmentdevelopmentproduction将此视为访问控制变更:先说明所需的确切规则,获得授权后再进行修改。不要扩大无关的环境配对范围。
Diagnose the response
诊断响应
- A Vercel login, SSO, or Deployment Protection page means the request did not use an accepted authentication path.
- means the token is valid but its caller environment is not allowed to reach the target environment.
TRUSTED_SOURCES_ENVIRONMENT_MISMATCH - An application-generated or
401after Vercel protection is bypassed belongs to the application's own authentication and must be debugged separately.403 - A deployment marked can still be protected. Do not assume production is public.
"target": "production"
- 出现Vercel登录、SSO或Deployment Protection页面,说明请求未使用被接受的身份验证路径。
- 表示令牌有效,但调用者的环境不被允许访问目标环境。
TRUSTED_SOURCES_ENVIRONMENT_MISMATCH - 绕过Vercel保护后出现应用程序生成的或
401状态码,属于应用程序自身的身份验证问题,需单独调试。403 - 标记为的部署仍可能受保护,不要假设生产环境是公开的。
"target": "production"
Avoid
注意事项
- Do not disable Deployment Protection to make automation pass.
- Do not send raw unauthenticated repeatedly after receiving the protection page.
curl - Do not start an interactive SSO browser login when or an origin-scoped OIDC header can authenticate the request.
vc curl - Do not expose in logs, screenshots, committed files, or user-facing output.
VERCEL_OIDC_TOKEN
- 不要为了让自动化流程通过而禁用Deployment Protection。
- 收到保护页面后,不要反复发送未认证的原生请求。
curl - 当或源范围OIDC请求头可完成身份验证时,不要启动交互式SSO浏览器登录。
vc curl - 不要在日志、截图、已提交文件或面向用户的输出中暴露。
VERCEL_OIDC_TOKEN
Related skills
相关技能
- General Vercel CLI usage:
⤳ skill: vercel-cli - End-to-end application verification:
⤳ skill: verification
- Vercel CLI通用用法:
⤳ skill: vercel-cli - 端到端应用验证:
⤳ skill: verification