Files
order-notification-automation/docs/superpowers/plans/2026-10-16-bpm-credentials.md
T

6.4 KiB
Raw Blame History

BPM Account Custody Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task.

Goal: 为实际 BPM 连接增加加密账号托管、Cookie 复用、自动保活/续登及持久 30 天工作台登录。 Architecture: 复用 AES-GCM/DPAPI vault 的独立 account:id 条目,API 只返回账号元数据,远程浏览器只在已验证登录控件填入。 Tech Stack: Existing Node CJS/Playwright/Tabler/vault. Spec: docs/superpowers/specs/2026-10-16-bpm-login-design.md 已授权的账号托管补充。

最新范围(取代下文旧版/双入口描述):用户明确只维护新版 BPM。仅 bpmn.skyworthdigital.com 与其 sso 登录跳转;移除旧版域名白名单、表单、导航、检查与 UI,portal 正向验证即 connected,checks 仅 portal,不再 partial。现有连接迁移去除旧字段,保留负责人、会话和业务数据。新版托管、30 天工作台会话、5 分钟保活与验证码人工介入继续适用。

Global Constraints

  • 用户已明确要求账号托管;不创建、重置或显示真实密码;用户在产品页面自行输入。
  • 不记录密码或截图;按用户后续明确要求自动托管,仅在正向确认需登录的已验证 SSO 表单提交凭据;不代解验证码,不修改 BPM 业务。
  • 继续保留正式管理员/主连接;不得动现有用户浏览器 Cookie。
  • 在当前非 Git 工作区工作,先有失败测试再实现;产品页面不出现设计思考文案。

Task 1: Managed account backend and fill

Files: src/bpm-session-manager.cjs, src/bpm-api.cjs, tests/bpm-account.test.cjs, tests/bpm-http.test.cjs (add tests, preserve existing).

Interfaces: manager.account(connection,principal) -> {configured,username,updatedAt}; manager.saveAccount(connection,principal,{username,password}) -> metadata; manager.clearAccount(connection,principal) -> {configured:false,username:'',updatedAt:null}; manager.fillAccount(connection,principal) -> {filled:boolean,message:string}. Same owner/admin authorization and perconnection serialization; save validates strict keys username nonempty<=150 chars/password nonempty<=256 chars, no trim of password. account:id vault entry stores username/password/updatedAt; return no password. manager.disable also removes account entry. save/clear don't require active browser; fill requires current session lease and drains queue. Production fill selectors only exact https://sso.skyworthdigital.com #username/#password and https://bpm.skyworthdigital.com #_txtUserId/#_txtPassword (allow injected fixture selectors through known-host constructor testing configuration only, never API). Fill only visible text/password input expected types, bounded wait, NEVER click submit. create/navigate internally attempt saved fill, unknown form no-op. When no account fill returns concise actionable error. Do not write back browser-field edits into account vault implicitly.

API: /api/connections/:id/account GET metadata, POST username/password save; /account/clear POST empty; /login/fill-account POST empty. Same role, same-origin POST and secureBpmTransport guards. GET metadata only authorized owner/admin. Only username metadata returned; no raw vault errors. Record audit save/clear using connection name (no password). Existing routes must remain unchanged.

  • Write failing persistence/auth/unknown-host/DOM-type/submit-never-called tests.
  • Implement methods and API routes.
  • Verify ciphertext contains neither username nor password, restart metadata/fill works, disable removes both, no secret response/audit.
  • Run focused tests and self-review.

Task 2: Account UI

Files: web/bpm.js, web/app.css, tests/bpm-ui.test.cjs.

Add 管理账号 to authorized connection cards. GET /connections/:id/account to show configured username or 未托管; an inline editor asks BPM账号 and 托管密码 (password type, autocomplete new-password, never prefilled stored value). 保存账号 POST same route; clear fields after success. Existing configured account updating requires entering a new password; placeholder 输入新密码以更新. 清除托管 POST account/clear; no account controls for viewers/unrelated operator/disabled connections. Remote toolbar offers 填入托管账号 when metadata says configured; serialize after input queue, track operation for disposal, standard busy/error controls. UI copy concise user actions only; no technical/internal disclaimers. Preserve all current input/lifecycle/CSP behavior.

  • Add meaningful failing UI tests for permissions, password handling and API body.
  • Implement form, metadata and fill action.
  • Verify no saved-password DOM value, no password in cards/localStorage, stale forms do not mount after navigation; run existing UI tests.

Task 3: Review, regression and deployment

Files: README.md, docs/verification.md, this plan ledger.

  • Independent read-only security/correctness review of account backend + UI.
  • Full suite and syntax pass; restart only verified project process and preserve existing data.
  • Show actual account management page. User enters actual account/password once; automatic checks and renewal operate thereafter, challenge handling remains in remote window. No test users in production.

Subsequent authorized scope: automatic custody and thirty days

用户明确要求“不要每一次都登入”“至少要30天有效”。以下规则取代前述任务中仅填入而不提交的限制:

  • manager.ensure 先验证已有 Cookie,健康时持久保存刷新状态,不提交凭据。只有正向确认登录页才尝试受限自动提交。网络失败、身份冲突、未知表单、验证码均不盲目重登;提交前持久化 15 分钟冷却。
  • 首次托管/同一托管账号更新密码保留有效会话;更换已托管用户名清除旧身份与会话。清除账号只删除托管凭据;停用删除会话与凭据。
  • 新增 BpmCustodian:启动即检查,每 5 分钟顺序检查,跳过人工操作租约和停用连接,关闭服务等待检查结束。没有业务动作或外部通知。
  • 新增 SessionStore:SQLite 仅持久 token 哈希,30 天滑动有效期,每日活动续期,重启可恢复,退出撤销。隔离演示/正式空间。
  • 外部 BPM 服务端有权撤销/强制过期,不伪造 Cookie 期限;使用保活和自动续登达到持续托管。实际 30 天运行尚需时间验证。