Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/downstream-enterprise-sso.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

独立企业应用的短期身份交换、后台应用管理及通用 `enterpriseAuth.app(appId).request()` API 见 [企业应用访问](downstream-enterprise-apps.md)。该扩展采用独立协议,需要配套后台与目标应用适配;下文的跨客户端边界仍成立。

## 企业服务地址与部署子路径

企业登录地址允许包含部署路径前缀,例如 https://example.com/team/bisheng。末尾斜线会统一移除;登录配置、授权、Token、平台 API 和聊天路由均保留该前缀。配置上述地址后,配置接口为 /team/bisheng/api/v1/dsh/config,授权页为 /team/bisheng/desktop-login,聊天入口位于 /team/bisheng/workspace。此处填写平台部署根地址,不填写某个登录页或 API 接口地址。

反向代理及平台返回的 authorize_url、页面路由和资源地址必须与部署前缀一致。仍拒绝地址内的账号密码、query 和 fragment,保留原有 HTTP 风险确认,并禁止请求跳出已确认站点和部署路径。服务端网页及静态资源也须按该前缀部署;客户端允许 path 不会自动重写服务器页面内的资源地址。

## 身份与信任边界

必须区分三个身份:用户/租户身份由企业认证服务确认;pluginId 来自经过授权的企业插件目录记录;instanceId 由可信宿主为每次加载生成。插件配置、插件提交的 userId、请求头以及插件 ID 字符串本身都不是身份凭据。
Expand Down
8 changes: 4 additions & 4 deletions packages/dsh-desktop-enterprise/contract.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHash, randomBytes, randomUUID } from 'node:crypto'
import { normalizeEnterpriseServerUrl } from './deep-link.js'
import { normalizeEnterpriseServerUrl, resolveEnterpriseUrl } from './deep-link.js'
export { normalizeAuditContext } from './audit-context.js'
export { parseAuditTitleUpdate } from './audit-title.js'
export { parseAuditFeedbackUpdate } from './audit-feedback.js'
Expand Down Expand Up @@ -134,7 +134,8 @@ export function parseAuthorization(value, base) {
if (!isObject(value)) throw new Error('BiSheng authorization response is invalid.')
const authId = requiredString(value.auth_id, 'authorization id', 256)
const authorizeUrl = new URL(requiredString(value.authorize_url, 'authorization URL', 4096))
if (authorizeUrl.origin !== base || authorizeUrl.pathname !== '/desktop-login') {
const expected = resolveEnterpriseUrl('/desktop-login', base)
if (authorizeUrl.origin !== expected.origin || authorizeUrl.pathname !== expected.pathname || authorizeUrl.username || authorizeUrl.password || authorizeUrl.hash) {
throw new Error('BiSheng authorization URL left the confirmed platform origin.')
}
if (authorizeUrl.searchParams.get('auth_id') !== authId) {
Expand Down Expand Up @@ -403,8 +404,7 @@ export async function requestJson(baseValue, path, options = {}) {
allowInsecureLoopback: options.allowInsecureLoopback === true,
allowInsecurePrivateHttp: options.allowInsecurePrivateHttp === true
})
const endpoint = new URL(path, `${base}/`)
if (endpoint.origin !== base) throw new Error('Enterprise request left the confirmed platform origin.')
const endpoint = resolveEnterpriseUrl(path, base)
const timeout = AbortSignal.timeout(options.timeoutMs ?? 15_000)
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout
let response
Expand Down
1 change: 1 addition & 0 deletions packages/dsh-desktop-enterprise/deep-link.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export declare function normalizeEnterpriseServerUrl(
value: string,
options?: EnterpriseUrlOptions
): string
export declare function resolveEnterpriseUrl(path: string, base: string): URL
export declare function parseEnterpriseLoginDeepLink(
value: string,
options?: EnterpriseUrlOptions
Expand Down
24 changes: 19 additions & 5 deletions packages/dsh-desktop-enterprise/deep-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,35 @@ export function normalizeEnterpriseServerUrl(value, options = {}) {
if (url.search || url.hash) {
throw new Error('The BiSheng platform address must not contain a query or fragment.')
}
if (url.pathname !== '/' && url.pathname !== '') {
throw new Error('The BiSheng platform address must be an origin without a path.')
}
const base = url.origin + url.pathname.replace(/\/+$/u, '')
if (url.protocol === 'https:') {
return url.origin
return base
}
if (url.protocol === 'http:') {
if (isLoopbackHost(url.hostname) || options.allowInsecurePrivateHttp === true) {
return url.origin
return base
}
throw new Error('HTTP addresses require explicit confirmation.')
}
throw new Error('The BiSheng platform address must use HTTP or HTTPS.')
}

/** Resolve platform routes below the configured reverse-proxy prefix. */
export function resolveEnterpriseUrl(path, base) {
const root = new URL(base)
const prefix = root.pathname.replace(/\/+$/u, '')
if (typeof path !== 'string' || path.startsWith('//') || /[\\\s]/u.test(path)) {
throw new Error('Enterprise request left the confirmed platform origin or base path.')
}
const target = new URL(path.replace(/^\//u, ''), root.origin + prefix + '/')
if (!['http:', 'https:'].includes(root.protocol) || root.username || root.password || root.search || root.hash ||
target.origin !== root.origin || target.username || target.password ||
(prefix && target.pathname !== prefix && !target.pathname.startsWith(prefix + '/'))) {
throw new Error('Enterprise request left the confirmed platform origin or base path.')
}
return target
}

export function parseEnterpriseLoginDeepLink(value, options = {}) {
let url
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type LandingElements = Omit<EnterpriseChatLandingGeometry, 'seat'>
/** Read the painted landing elements only after Chromium has applied the native seat resize. */
export function chatLandingGeometryScript(url: string, width: number, height: number): string {
return `(() => {
if (location.href !== ${JSON.stringify(url)} || location.pathname !== '/workspace/c/new') return;
if (location.href !== ${JSON.stringify(url)} || location.pathname !== ${JSON.stringify(new URL(url).pathname)}) return;
if (Math.abs(innerWidth - ${width}) > 1 || Math.abs(innerHeight - ${height}) > 1) return null;
const landing = document.querySelector('.dsh-chat-surface .dsh-chat-landing');
const title = landing?.querySelector('.dsh-chat-headline');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const FADE_IN_MS = 135
/** The isolated Chat document animates its own writing region without exporting any text. */
export function chatLandingTextMotionScript(url: string, phase: 'out' | 'in', revision: number, deadline: number): string {
return `(() => {
if (location.href !== ${JSON.stringify(url)} || location.pathname !== '/workspace/c/new' || Date.now() > ${deadline}) return;
if (location.href !== ${JSON.stringify(url)} || location.pathname !== ${JSON.stringify(new URL(url).pathname)} || Date.now() > ${deadline}) return;
const previous = window.__dshChatLandingTextMotion;
if (previous && previous.revision >= ${revision}) return;
previous?.animation?.cancel();
Expand Down
6 changes: 4 additions & 2 deletions packages/dsh-desktop-enterprise/desktop/chat-module-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const MODULE_ROUTE_PATTERN = '^/workspace/(capabilities|knowledge|channel
* (utility overrides apply there too, Chat included); `dsh-module-dark` is the module-only
* scope where the host owns `html.dark`.
*/
export function moduleThemeScript(theme: EnterpriseChatPresentation['theme'], palette?: EnterprisePalette): string {
export function moduleThemeScript(theme: EnterpriseChatPresentation['theme'], palette?: EnterprisePalette, basePath = '/'): string {
return `(() => {
const root = document.documentElement;
root.dataset.dshHostTheme = '${theme}';
Expand Down Expand Up @@ -55,7 +55,9 @@ export function moduleThemeScript(theme: EnterpriseChatPresentation['theme'], pa
}
};
const apply = () => {
const page = (location.pathname.match(pattern) || [])[1] || '';
const prefix = ${JSON.stringify(basePath.replace(/\/+$/u, ''))};
const pathname = !prefix ? location.pathname : location.pathname.startsWith(prefix + '/') ? location.pathname.slice(prefix.length) : '';
const page = (pathname.match(pattern) || [])[1] || '';
if ((root.dataset.dshPage || '') !== page) { if (page) root.dataset.dshPage = page; else delete root.dataset.dshPage; }
const hostDark = root.dataset.dshHostTheme === 'dark';
const dark = hostDark && page !== '';
Expand Down
Loading
Loading