-
Notifications
You must be signed in to change notification settings - Fork 0
chore: harden CI and Qinglong dependency setup #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,20 @@ const { classifyFailure, classifySummary, summarizeError } = require(path.join(_ | |
| const ROOT = path.resolve(__dirname, '..') | ||
| const MAIN = path.join(ROOT, 'xbk_function_v3.js') | ||
|
|
||
| function shouldAutoInstallDependencies (env = process.env) { | ||
| return env && env.XBK_AUTO_INSTALL_DEPS === '1' | ||
| } | ||
|
|
||
| function ensureDependencies () { | ||
| try { | ||
| // 不只检查 require.resolve:got 的传递依赖缺失时,真正 require 才能发现。 | ||
| require(path.join(ROOT, 'node_modules', 'got')) | ||
| return | ||
| } catch (e) { | ||
| console.warn('检测到 Node.js 依赖未完整安装,正在安装 got 依赖...') | ||
| if (!shouldAutoInstallDependencies()) { | ||
| throw new Error('检测到 Node.js 依赖未完整安装;请在部署阶段执行 npm ci --omit=dev --ignore-scripts。如确需在本次运行时安装,请显式设置 XBK_AUTO_INSTALL_DEPS=1') | ||
| } | ||
| console.warn('检测到 Node.js 依赖未完整安装,已按 XBK_AUTO_INSTALL_DEPS=1 执行安装...') | ||
|
Comment on lines
16
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- qinglong/xbk_push.js (relevant ranges) ---'
sed -n '1,45p' qinglong/xbk_push.js
sed -n '145,180p' qinglong/xbk_push.js
printf '%s\n' '--- dependency and install references ---'
rg -n -C 3 'ensureDependencies|shouldAutoInstallDependencies|npm (ci|install)|MODULE_NOT_FOUND|XBK_AUTO_INSTALL_DEPS' qinglong package.json package-lock.json 2>/dev/null || trueRepository: gghhffgfd4yy6/notes Length of output: 5259 🏁 Script executed: #!/bin/bash
set -eu
node - <<'JS'
'use strict'
const Module = require('node:module')
function loadWithCurrentPolicy(load, autoInstall) {
try {
load()
return 'loaded'
} catch (e) {
if (!autoInstall) return 'dependency-error'
return 'install-triggered'
}
}
function loadWithProposedPolicy(load, autoInstall) {
try {
load()
return 'loaded'
} catch (e) {
if (!e || e.code !== 'MODULE_NOT_FOUND') throw e
if (!autoInstall) return 'dependency-error'
return 'install-triggered'
}
}
const missing = () => {
const error = new Error('missing dependency')
error.code = 'MODULE_NOT_FOUND'
throw error
}
const initializationFailure = () => {
throw new Error('module initialization failed')
}
const syntaxFailure = () => {
const module = new Module('/virtual/module.js')
module._compile('const =', '/virtual/module.js')
}
for (const [name, loader] of [
['missing dependency', missing],
['initialization failure', initializationFailure],
['syntax failure', syntaxFailure]
]) {
let current
let proposed
try { current = loadWithCurrentPolicy(loader, true) } catch (e) { current = `rethrows:${e.code || e.name}` }
try { proposed = loadWithProposedPolicy(loader, true) } catch (e) { proposed = `rethrows:${e.code || e.name}` }
console.log(`${name}: current=${current}; proposed=${proposed}`)
}
JSRepository: gghhffgfd4yy6/notes Length of output: 379 Re-throw non-missing-module errors.
Apply the installation policy only when 🧰 Tools🪛 ast-grep (0.45.1)[warning] 18-18: Avoid require with non-literal values (detect-non-literal-require) 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm' | ||
|
|
@@ -158,4 +165,4 @@ if (require.main === module) { | |
| }) | ||
| } | ||
|
|
||
| module.exports = { classifyFailure, classifySummary, runResident, refreshConnections, intervalMs } | ||
| module.exports = { classifyFailure, classifySummary, runResident, refreshConnections, intervalMs, shouldAutoInstallDependencies } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: gghhffgfd4yy6/notes
Length of output: 7511
🏁 Script executed:
Repository: gghhffgfd4yy6/notes
Length of output: 4642
🌐 Web query:
actions/checkout v4 persist-credentials default .git/config README💡 Result:
In actions/checkout v4, the persist-credentials input defaults to true [1][2]. This setting configures the authentication token (or SSH key) used for the checkout into the local git configuration, allowing subsequent workflow steps to perform authenticated git commands [3][4]. Regarding where these credentials are stored: 1. Traditional behavior: By default, in earlier v4 releases, this action wrote the authentication token directly into the repository's.git/config file as an http.https://github.com/.extraheader value [5]. This meant that if the.git directory was included in an artifact upload, the token could be inadvertently exposed [5]. 2. Updated behavior (v4.2.0+): A significant update (introduced in PR
#2286) changed how these credentials are persisted to improve security [6][5]. Instead of writing them directly into.git/config, the action now stores credentials in a separate file within the runner's temporary directory ($RUNNER_TEMP) and adds an includeIf.gitdir configuration to.git/config that points to that file [6][5]. This prevents the token from being captured in artifact uploads that only include the workspace's.git directory [5]. To opt out of this behavior, you can set persist-credentials: false in your workflow file, which prevents the action from writing the credentials to disk entirely [3][5].Citations:
persist-credentials: falseon checkout steps cli/go-gh#225🏁 Script executed:
Repository: gghhffgfd4yy6/notes
Length of output: 3305
Disable checkout credential persistence
actions/checkoutpersists authentication credentials by default. Later repository code can use them for authenticated Git operations. Addpersist-credentials: false; theghcommand already receivesGH_TOKENexplicitly.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 zizmor (1.29.0)
[warning] 17-17: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
🤖 Prompt for AI Agents
Source: Linters/SAST tools