T06 · System Persistence
Error
- Location
- scripts/init.sh:42
- Finding
- Persistent execution of code outside the audited Skill package<![CDATA[ ## Vulnerability Details **File Location**: `scripts/init.sh`, lines 42-76 **Vulnerability Type**: Persistent service registration **Risk Level**: High ### Vulnerable Code ```bash # 4. 通过 Supervisor 注册(如果已安装 Supervisor) if command -v python3 &> /dev/null && python3 -c "import supervisor" 2>/dev/null; then SUPERVISOR_CONF="${HOME}/supervisord.conf" if [ -f "${SUPERVISOR_CONF}" ]; then if ! grep -q "token-broker" "${SUPERVISOR_CONF}" 2>/dev/null; then warn "未在 Supervisor 中找到 token-broker,尝试注册..." # 尝试通过 supervisord 提供的 rpc 接口添加 echo " [program:token-broker] command=npx ts-node ${BROKER_DIR}/src/server.ts directory=${BROKER_DIR} autostart=true autorestart=true startsecs=5 startretries=10 stopwaitsecs=5 killasgroup=true stopsignal=TERM stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 environment=BROKER_PORT=${BROKER_PORT},NODE_ENV=production" >> "${SUPERVISOR_CONF}" info "已追加到 Supervisor 配置" python3 -m supervisor.supervisorctl -c "${SUPERVISOR_CONF}" reread 2>/dev/null || true python3 -m supervisor.supervisorctl -c "${SUPERVISOR_CONF}" update 2>/dev/null || true sleep 2 else info "Supervisor 中已配置 TokenBroker" python3 -m supervisor.supervisorctl -c "${SUPERVISOR_CONF}" start token-broker 2>/dev/null || true sleep 2 fi fi fi ``` ### Technical Analysis The initialization script appends a new program definition to the user's persistent Supervisor configuration. The definition enables both `autostart` and `autorestart`, causing `${BROKER_DIR}/src/server.ts` to execute beyond the lifetime of the installer and to restart automatically after failure or a Supervisor restart. The executed broker source is located in the sibling directory `../../production-system/token-broker` rather than inside the audited Skill. That source code is not included in the project under review, so its behavior and integrity cannot be verified as par ...[truncated 1425 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not create a persistent Supervisor service by default. Require explicit, informed user consent before modifying startup configuration. 2. Keep executable broker code inside a reviewed, versioned package rather than resolving it from a sibling directory. 3. Verify the broker artifact using a cryptographic digest or signature before registering or executing it. 4. Invoke a pinned executable through an absolute path instead of relying on `npx` and ambient package resolution. 5. Generate a dedicated Supervisor configuration file rather than appending text to a shared `~/supervisord.conf`. 6. Display the exact configuration and executable path before installation and provide an explicit uninstall operation that stops the service and removes its configuration. 7. Run the broker under a dedicated, least-privileged account with narrowly scoped filesystem and network permissions where supported. 8. Do not suppress failures from `supervisorctl`; abort and report an actionable error if registration cannot be verified. ]]>
