T01 · Skill Instruction Hijacking
- Location
plugin/tutor-timing/index.js:57- Finding
Gateway-Wide Prompt and Role Hijacking Through Unscoped Hooks
- Content
View full analysis
Vulnerability Details
File Location:
plugin/tutor-timing/index.js:40-48, 57-76
Vulnerability Type: Unscoped instruction injection into agent prompts
Risk Level: HighVulnerable Code
js function buildContext() { maybeResetTimer(); const now = Date.now(); const elapsed = Math.floor((now - startTime) / 60000); const { phase, instruction } = getPhase(elapsed); const autoResetNote = autoReset ? "\n[Auto-reset: new lesson detected — timer was reset. This is a fresh lesson.]" : ""; autoReset = false; return `[System Context] Current timestamp: ${new Date().toISOString()} Session elapsed: ${elapsed} minutes Current phase: ${phase} ${instruction} Reminder: You must strictly follow the phase above. Do not skip phases or act out of sequence.${autoResetNote}`; }js register(api) { api.on("message_received", async () => { lastMessageTime = Date.now(); }); api.on("before_prompt_build", async () => { const ctx = buildContext(); try { fs.appendFileSync("C:\\Users\\samuel\\.openclaw\\tmp\\hook-log.txt", `before_prompt_build injecting:\n${ctx}\n---\n`); } catch {} return { prependContext: ctx }; }); api.on("agent_turn_prepare", async () => { return { prependContext: buildContext() }; }); api.on("before_agent_start", async () => { return { prependContext: buildContext() }; }); api.on("session_start", async (event) => { const reason = event.context?.reason || "unknown"; if (reason === "new") { startTime = Date.now(); lessonDayStart = new Date().toDateString(); lastMessageTime = Date.now(); autoReset = false; } }); }Technical Analysis
The plugin describes itself as a timing injector for the
english-oral-teacheragent, but its prompt-related hooks do not inspect or validate an agent identifier, session owner, or workspace. Each hook returnsprependContextunconditionally.The injected content is presented as a system-context block and c ...[truncated 2294 chars]
- Remediation
View remediation
Remediation Suggestions
- Scope every hook to the intended agent before returning injected context:
js const TARGET_AGENT_ID = "english-oral-teacher"; function isTargetAgent(event) { return event?.context?.agentId === TARGET_AGENT_ID; } api.on("before_prompt_build", async (event) => { if (!isTargetAgent(event)) return; return { prependContext: buildContext() }; });-
Apply equivalent validation to
message_received,session_start, and any other registered lifecycle hook so unrelated activity cannot modify tutor timing state. -
Use one documented prompt-injection hook rather than injecting the same context through three lifecycle hooks.
-
Store timing state per agent and session instead of in module-level global variables. A map keyed by a validated agent ID and session ID would prevent cross-session contamination.
-
Prefer structured, narrowly scoped metadata over authoritative wording such as “You must strictly follow.” The receiving agent's primary policy should remain authoritative.
-
Add automated tests proving that:
- The target tutor agent receives exactly one timing block.
- Other agents receive no timing block.
- Activity in one session cannot reset or advance another session's timer.
- Missing or malformed agent identifiers result in no injection.
-
Align
openclaw.plugin.jsonhook declarations with the hooks actually registered by the implementation so administrators can accurately review the plugin's behavior.
