-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(onboard): accept WeChat account token placeholder #9479
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fbc4712
fix(onboard): accept WeChat account token placeholder
ericksoa 849109c
fix(onboard): bind WeChat token placeholder contract
ericksoa 2af0085
test(onboard): cover unsafe WeChat account paths
ericksoa 2bc75fd
refactor(messaging): own managed placeholder contract
ericksoa 87f02ee
fix(messaging): resolve WeChat hook in stripped runtime
ericksoa 36c748d
refactor(messaging): authorize placeholders through registries
ericksoa 626b83a
chore(messaging): drop unused contract import
ericksoa fb188d3
fix: preserve standalone managed profile runtime
ericksoa b6a6519
refactor: remove unused placeholder registry path
ericksoa 86af005
Merge origin/main into fix/managed-messaging-content-token-9397
ericksoa 8b9a9ee
test: align messaging plan fixture with agent validation
ericksoa 5158769
merge: resolve conflicts with main
github-actions[bot] 3d10770
test: retain upstream messaging plan fixture
ericksoa 7a969d2
merge: restore narrow profile diff from current main
ericksoa 6d74283
fix(messaging): require private WeChat account files
prekshivyas 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Schema-owned identity for the WeChat account-file build output. | ||
| * | ||
| * The manifest, hook registration, and standalone managed-startup validator all | ||
| * consume this dependency-free contract. Keeping it free of imports is required | ||
| * because the validator also runs directly under Node's stripped-types loader. | ||
| */ | ||
| export const WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT = { | ||
| channelId: "wechat", | ||
| planHookId: "wechat-seed-openclaw-account", | ||
| handlerId: "wechat.seedOpenClawAccount", | ||
| outputId: "openclawWeixinAccountFile", | ||
| kind: "build-file", | ||
| required: true, | ||
| } as const; | ||
|
|
||
| export const WECHAT_SEED_OPENCLAW_ACCOUNT_HOOK_ID = WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT.handlerId; | ||
| export const WECHAT_SEED_OPENCLAW_ACCOUNT_PLAN_HOOK_ID = | ||
| WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT.planHookId; | ||
| export const WECHAT_OPENCLAW_ACCOUNT_FILE_OUTPUT_ID = | ||
| WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT.outputId; | ||
|
|
||
| export const WECHAT_TOKEN_PLACEHOLDER = "openshell:resolve:env:WECHAT_BOT_TOKEN"; | ||
|
|
||
| export interface WechatManagedStartupPlaceholderAuthorization { | ||
| readonly path: readonly string[]; | ||
| readonly value: string; | ||
| } | ||
|
|
||
| export function authorizeWechatAccountFilePlaceholders( | ||
| value: unknown, | ||
| ): readonly WechatManagedStartupPlaceholderAuthorization[] { | ||
| if (!isPlainDataObject(value) || !isWechatAccountFilePath(ownDataPropertyValue(value, "path"))) { | ||
| return []; | ||
| } | ||
| return [{ path: ["content", "token"], value: WECHAT_TOKEN_PLACEHOLDER }]; | ||
| } | ||
|
|
||
| export function wechatAccountFilePath(accountId: string): string { | ||
| return `openclaw-weixin/accounts/${accountId}.json`; | ||
| } | ||
|
|
||
| export function assertSafeWechatAccountId(accountId: string): void { | ||
| if (!isSafeWechatAccountId(accountId)) { | ||
| throw new Error("WeChat account id contains unsafe filename characters."); | ||
| } | ||
| } | ||
|
|
||
| function isWechatAccountFilePath(value: unknown): boolean { | ||
| if (typeof value !== "string") return false; | ||
| const prefix = "openclaw-weixin/accounts/"; | ||
| const suffix = ".json"; | ||
| if (!value.startsWith(prefix) || !value.endsWith(suffix)) return false; | ||
| const accountId = value.slice(prefix.length, -suffix.length); | ||
| return accountId === accountId.trim() && isSafeWechatAccountId(accountId); | ||
| } | ||
|
|
||
| function isSafeWechatAccountId(accountId: string): boolean { | ||
| return ( | ||
| accountId.length > 0 && | ||
| accountId !== "." && | ||
| accountId !== ".." && | ||
| !/[\\/\0-\x1F\x7F]/.test(accountId) && | ||
| !accountId.includes("..") | ||
| ); | ||
| } | ||
|
|
||
| function isPlainDataObject(value: unknown): value is Record<string, unknown> { | ||
| return ( | ||
| value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype | ||
| ); | ||
| } | ||
|
|
||
| function ownDataPropertyValue(value: Record<string, unknown>, key: string): unknown { | ||
| const descriptor = Object.getOwnPropertyDescriptor(value, key); | ||
| return descriptor && "value" in descriptor ? descriptor.value : undefined; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { | ||
| authorizeWechatAccountFilePlaceholders, | ||
| WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT, | ||
| type WechatManagedStartupPlaceholderAuthorization, | ||
| } from "./channels/wechat/contract.ts"; | ||
|
|
||
| export type MessagingManagedStartupPlaceholderAuthorization = | ||
| WechatManagedStartupPlaceholderAuthorization; | ||
|
|
||
| export function authorizeMessagingManagedStartupPlaceholders( | ||
| step: unknown, | ||
| ): readonly MessagingManagedStartupPlaceholderAuthorization[] { | ||
| if (!isPlainDataObject(step)) return []; | ||
| const contract = WECHAT_OPENCLAW_ACCOUNT_FILE_CONTRACT; | ||
| if ( | ||
| ownDataPropertyValue(step, "channelId") !== contract.channelId || | ||
| ownDataPropertyValue(step, "hookId") !== contract.planHookId || | ||
| ownDataPropertyValue(step, "handler") !== contract.handlerId || | ||
| ownDataPropertyValue(step, "outputId") !== contract.outputId || | ||
| ownDataPropertyValue(step, "kind") !== contract.kind || | ||
| ownDataPropertyValue(step, "required") !== contract.required | ||
| ) { | ||
| return []; | ||
| } | ||
|
|
||
| return authorizeWechatAccountFilePlaceholders(ownDataPropertyValue(step, "value")).map( | ||
| (authorization) => ({ | ||
| ...authorization, | ||
| path: ["value", ...authorization.path], | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| function isPlainDataObject(value: unknown): value is Record<string, unknown> { | ||
| return ( | ||
| value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype | ||
| ); | ||
| } | ||
|
|
||
| function ownDataPropertyValue(value: Record<string, unknown>, key: string): unknown { | ||
| const descriptor = Object.getOwnPropertyDescriptor(value, key); | ||
| return descriptor && "value" in descriptor ? descriptor.value : undefined; | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.