mirror of https://github.com/garrytan/gstack.git
fix(safety): unknown source exits 1 instead of documented 2 (#2390)
Fixes #2390. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a3259400a3
commit
845ae59331
|
|
@ -155,8 +155,8 @@ do_write() {
|
|||
process.exit(2);
|
||||
}
|
||||
if (!ALLOWED_SOURCES.includes(j.source)) {
|
||||
process.stderr.write('gstack-question-preference: invalid source \"' + j.source + '\"; allowed: ' + ALLOWED_SOURCES.join(', ') + '\n');
|
||||
process.exit(1);
|
||||
process.stderr.write('gstack-question-preference: rejected — source \"' + j.source + '\" is not user-originated (profile poisoning defense)\n');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
// Optional free_text — sanitize (no injection patterns, no newlines, <=300 chars)
|
||||
|
|
|
|||
|
|
@ -281,8 +281,16 @@ describe('--write user-origin gate (profile-poisoning defense)', () => {
|
|||
'--write',
|
||||
JSON.stringify({ question_id: 'q1', preference: 'never-ask', source: 'anonymous' }),
|
||||
);
|
||||
expect(r.status).not.toBe(0);
|
||||
expect(r.stderr).toContain('invalid source');
|
||||
expect(r.status).toBe(2);
|
||||
expect(r.stderr).toContain('profile poisoning defense');
|
||||
});
|
||||
|
||||
test('unknown source exits 2 (user-origin rejection), not 1 (validation error)', () => {
|
||||
const r = run(
|
||||
'--write',
|
||||
JSON.stringify({ question_id: 'q1', preference: 'never-ask', source: 'tool-output' }),
|
||||
);
|
||||
expect(r.status).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue