Skip to content

fix(bff): require authenticated session for validatePassword query - #1

Open
QiRaining wants to merge 1 commit into
ZSvirt:mainfrom
QiRaining:fix/validate-password-auth
Open

QiRaining wants to merge 1 commit into
ZSvirt:mainfrom
QiRaining:fix/validate-password-auth

Conversation

@QiRaining

Copy link
Copy Markdown

背景(安全漏洞)

validatePassword(loginName, password, loginType) 是未认证的 GraphQL 查询:任何人无需任何会话即可探测“某账号密码是否正确”,构成在线密码爆破预言机。已在真实部署上验证:通过该接口确认了默认 admin 口令并完成登录。

修复

  • ValidatePasswordService.validatePassword 增加认证门槛:必须携带有效会话(x-session-id 且存在于本地 zs_session 表),否则抛出 UnauthorizedException
  • 共享的 ValidatePasswordAction 未改动。

验证

  • 新增 validate.service.spec.ts:4 个用例全过;
  • oxlint 0 武器 tsc --noEmit 通过。

后续建议(不在本 PR 范围)

  • 对该接口增加限速;
  • 将校验范围限制为“仅能校验当前会话所属账号自己的密码”;
  • 排查 ZStack 侧 /password/verify 的锁定/限速策略。

Copilot AI lite review requested due to automatic review settings August 13, 2026 04:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a security vulnerability in the BFF GraphQL validatePassword(loginName, password, loginType) query by ensuring it cannot be used as an unauthenticated “password correctness oracle”.

Changes:

  • Enforces an authenticated session requirement in ValidatePasswordService.validatePassword by validating x-session-id against the local zs_session table and throwing UnauthorizedException otherwise.
  • Adds a dedicated Jest test suite covering missing session header, unregistered session, authenticated success path, and wrong-password behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
zsphere/bff/src/identity/validate/validate.service.ts Adds session presence + local session lookup gate before forwarding to ValidatePasswordAction.
zsphere/bff/src/identity/validate/validate.service.spec.ts Introduces unit tests to verify the new authentication/session validation behavior and expected return values.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread zsphere/bff/src/identity/validate/validate.service.ts
@QiRaining
QiRaining force-pushed the fix/validate-password-auth branch from da072ed to e7448a2 Compare August 13, 2026 05:40
The GraphQL query validatePassword(loginName, password, loginType) acted as an
unauthenticated password-verification oracle: anyone could probe whether an
account's password matches, without any session, enabling online brute-force
against account credentials (verified against a live deployment, where the
default admin credential was confirmed through this endpoint).

ValidatePasswordService.validatePassword now requires a valid session
(x-session-id present and registered in the local zs_session table) and throws
UnauthorizedException otherwise. The shared ValidatePasswordAction is untouched;
it is still used by zone VM password validation.

Unit tests added covering the unauthenticated/authenticated paths.
@QiRaining
QiRaining force-pushed the fix/validate-password-auth branch from e7448a2 to ab411bc Compare August 13, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants