PR build: add dispatch script & secure workflow
Introduce a safe PR build dispatch flow and related helpers. - Add GitHubAPI.createWorkflowDispatch to .github/scripts/lib/github.ts and tighten getRepository nullability. - Add .github/scripts/pr-build-dispatch.ts to dispatch an untrusted workflow_run (workflow_dispatch) for PR builds. - Rewrite .github/workflows/build-pr.yml to split privileged checks (pull_request_target / issue_comment) from untrusted execution (workflow_dispatch): - Add workflow_dispatch inputs for PR metadata. - Ensure privileged jobs only check conditions, post comments and dispatch the untrusted build. - Untrusted build jobs (framework/shell/publish) run under workflow_dispatch, checkout PR code into a separate workspace, clear GITHUB_TOKEN in build steps, and set stricter permissions and persist-credentials:false where appropriate. - Adjust concurrency, outputs, and inter-job dependencies to work with inputs rather than passing sensitive data between privileged and untrusted contexts. - Update trigger-docker and result-comment flows to rely on workflow_dispatch inputs and only run in the untrusted run where appropriate. - Change packages/napcat-vite/vite-plugin-version.js to read NAPCAT_GITHUB_TOKEN (instead of GITHUB_TOKEN) to avoid exposing Actions write tokens in untrusted builds. These changes aim to improve security by preventing execution of PR-controlled code with elevated repo permissions and by isolating token usage.
This commit is contained in:
1 parent
1c703a60ed
commit
b058604077
4 files changed
+244
-179
No files matched your search
@@ -47,8 +47,8 @@ function validateVersion (version) {
|
||||
* 版本号来源优先级:
|
||||
* 1. 环境变量 NAPCAT_VERSION (用于 CI 构建)
|
||||
* 2. 缓存的 GitHub tag
|
||||
* 3. 从 GitHub API 获取最新 tag
|
||||
* 4. 兆底版本号: 1.0.0-dev
|
||||
* 3. 从 GitHub API 获取最新公开 tag(不携带 token)
|
||||
* 4. 兜底版本号: 1.0.0-dev
|
||||
*/
|
||||
export default function vitePluginNapcatVersion () {
|
||||
const pluginDir = path.resolve(__dirname, 'dist');
|
||||
@@ -56,7 +56,6 @@ export default function vitePluginNapcatVersion () {
|
||||
const owner = 'NapNeko';
|
||||
const repo = 'NapCatQQ';
|
||||
const maxAgeMs = 24 * 60 * 60 * 1000; // cache 1 day
|
||||
const githubToken = process.env.GITHUB_TOKEN;
|
||||
// CI 构建时可通过环境变量直接指定版本号
|
||||
const envVersion = process.env.NAPCAT_VERSION;
|
||||
const fallbackVersion = '1.0.0-dev';
|
||||
@@ -92,7 +91,6 @@ export default function vitePluginNapcatVersion () {
|
||||
headers: {
|
||||
'User-Agent': 'vite-plugin-napcat-version',
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
...(githubToken ? { Authorization: `token ${githubToken}` } : {}),
|
||||
},
|
||||
},
|
||||
(res) => {
|
||||
|
||||
Reference in new issue
Block a user