Everything that was uncommitted in the shared tree, in one commit because the changes are interleaved across the same files (lcm, engine, frontend, locales). lcm: a continuation prompt is not the task. After /resume the newest user message is "Continue with the task ...", and pinning it kept the keystroke while the question it continues was cut away -- measured: a resumed session woke up with the prompt, one tool call and its error, and no task at all. The pin now skips the harness's own continuation prompts, so the real question is pinned again. test_compactor drives it: with the skip disabled the task is lost (red), with it the task comes back after the summary (green). engine: /self-check and the exact tool-argument parse are in a1794fb; this commit carries the tests for them (a failed tool observation must appear in the self-check prompt; mcp_parse_exact rejects two objects in one string) and the i18n keys the new code uses: cmd.script.*, main.no_profile, tg.busy, tg.interview.running, ui.agent_busy in all three catalogues. The rest is the in-flight work from the shared session: engine/frontend, plugins, telegram/a2a, and their tests. make check: all tests passed; check_i18n ok, 204 keys in 3 catalogues.
171 lines
5.5 KiB
C
171 lines
5.5 KiB
C
/*
|
|
* splinter -- kid mode's gate, against the ways it was found to open.
|
|
*
|
|
* - the whitelist was matched against the raw JSON, so "run ls*" never
|
|
* matched; and a working glob over a shell command would have allowed
|
|
* "ls; anything";
|
|
* - the parent was asked through system("cmd 'Anfrage: <args>'"), so a
|
|
* quote in the model's arguments ran a command before anybody answered;
|
|
* - the domain list took "allowed.org:x@evil.example" for allowed.org;
|
|
* - SPLINTER_KIDS_TIMEOUT was ignored by the approve command: a parent
|
|
* who never answered kept the child waiting forever;
|
|
* - with the daily budget gone, reading and the domain list still passed.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_plugin.h"
|
|
|
|
static int failures;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static void
|
|
put(const char *path, const char *text)
|
|
{
|
|
FILE *f = fopen(path, "w");
|
|
|
|
CHECK(f != NULL);
|
|
if (f != NULL) {
|
|
fputs(text, f);
|
|
fclose(f);
|
|
}
|
|
}
|
|
|
|
static int
|
|
gate(struct sp_host *h, const char *tool, int auth, const char *args)
|
|
{
|
|
char reason[256] = "";
|
|
|
|
return sp_host_gate(h, tool, auth, args, reason, sizeof(reason));
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
char home[] = "/var/tmp/splinter-kids-XXXXXX";
|
|
char path[700], mark[700], args[1200], cmd[800];
|
|
struct sp_registry reg;
|
|
struct sp_agent ag;
|
|
struct sp_host *host;
|
|
struct sp_buf err;
|
|
struct stat st;
|
|
|
|
CHECK(mkdtemp(home) != NULL);
|
|
snprintf(path, sizeof(path), "%s/.splinter", home);
|
|
(void)mkdir(path, 0700);
|
|
snprintf(path, sizeof(path), "%s/.splinter/kids", home);
|
|
(void)mkdir(path, 0700);
|
|
snprintf(path, sizeof(path), "%s/.splinter/kids/allow", home);
|
|
put(path, "run ls*\n");
|
|
snprintf(path, sizeof(path), "%s/.splinter/kids/domains", home);
|
|
put(path, "allowed.org\n");
|
|
snprintf(mark, sizeof(mark), "%s/pwned", home);
|
|
|
|
(void)setenv("HOME", home, 1);
|
|
(void)unsetenv("SPLINTER_ACK_CHANNELS");
|
|
(void)unsetenv("SPLINTER_ACK_DIR");
|
|
(void)setenv("SPLINTER_KIDS_APPROVE_CMD", "exit 1", 1); /* parent says no */
|
|
(void)setenv("SPLINTER_KIDS_TIMEOUT", "2", 1);
|
|
(void)setenv("SPLINTER_KIDS_SEARCH", "approve", 1);
|
|
|
|
memset(®, 0, sizeof(reg));
|
|
memset(&ag, 0, sizeof(ag));
|
|
CHECK(sp_buf_init(&err) == 0);
|
|
host = sp_host_new(®, &ag, NULL);
|
|
CHECK(host != NULL);
|
|
if (host == NULL)
|
|
return 1;
|
|
CHECK(sp_plugin_load(host, "plugins/kids/kids.so", &err) == 0);
|
|
|
|
/* ---- the whitelist sees the command, not the JSON ---- */
|
|
CHECK(gate(host, "run", SP_AUTH_DESTRUCTIVE,
|
|
"{\"command\":\"ls -la\"}") == 1);
|
|
/* ---- and a command that chains is a parent's decision ---- */
|
|
CHECK(gate(host, "run", SP_AUTH_DESTRUCTIVE,
|
|
"{\"command\":\"ls; rm -rf ~\"}") == 0);
|
|
CHECK(gate(host, "run", SP_AUTH_DESTRUCTIVE,
|
|
"{\"command\":\"ls $(rm -rf ~)\"}") == 0);
|
|
CHECK(gate(host, "run", SP_AUTH_DESTRUCTIVE,
|
|
"{\"command\":\"cat /etc/shadow\"}") == 0);
|
|
|
|
/* ---- asking the parent does not run the model's text ---- */
|
|
snprintf(args, sizeof(args), "{\"path\":\"x'; touch %s; echo '\"}", mark);
|
|
CHECK(gate(host, "write", SP_AUTH_MUTATE, args) == 0);
|
|
CHECK(stat(mark, &st) != 0);
|
|
|
|
/* ---- the domain list names hosts, not user names ---- */
|
|
CHECK(gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://allowed.org/page\"}") == 1);
|
|
CHECK(gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://allowed.org:x@evil.example/\"}") == 0);
|
|
CHECK(gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://allowed.org.evil.example/\"}") == 0);
|
|
/* two "url" keys: checked and fetched must be the same one */
|
|
CHECK(gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://allowed.org/\",\"url\":\"https://evil.example/\"}")
|
|
== 0 || gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://evil.example/\",\"url\":\"https://allowed.org/\"}")
|
|
== 0);
|
|
|
|
sp_host_free(host);
|
|
|
|
/* ---- a parent who does not answer is a NO, after the timeout ---- */
|
|
(void)setenv("SPLINTER_KIDS_APPROVE_CMD", "sleep 30;", 1);
|
|
(void)setenv("SPLINTER_KIDS_TIMEOUT", "1", 1);
|
|
(void)setenv("SPLINTER_KIDS_DAILY_MINUTES", "1", 1);
|
|
host = sp_host_new(®, &ag, NULL);
|
|
CHECK(host != NULL);
|
|
if (host == NULL)
|
|
return 1;
|
|
sp_buf_clear(&err);
|
|
CHECK(sp_plugin_load(host, "plugins/kids/kids.so", &err) == 0);
|
|
{
|
|
time_t t0 = time(NULL);
|
|
char reason[256] = "";
|
|
|
|
CHECK(sp_host_gate(host, "write", SP_AUTH_MUTATE,
|
|
"{\"path\":\"x\"}", reason, sizeof(reason)) == 0);
|
|
CHECK(time(NULL) - t0 < 10);
|
|
CHECK(strstr(reason, "Zeit abgelaufen") != NULL);
|
|
}
|
|
/* within the budget, reading is free */
|
|
CHECK(gate(host, "read", SP_AUTH_READ, "{\"path\":\"x\"}") == 1);
|
|
|
|
/* ---- the day is over: nothing passes, not even reading ---- */
|
|
{
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
char day[16], line[64];
|
|
|
|
(void)localtime_r(&now, &tm);
|
|
strftime(day, sizeof(day), "%Y-%m-%d", &tm);
|
|
snprintf(line, sizeof(line), "%s 99999\n", day);
|
|
snprintf(path, sizeof(path), "%s/.splinter/kids/usage", home);
|
|
put(path, line);
|
|
}
|
|
CHECK(gate(host, "read", SP_AUTH_READ, "{\"path\":\"x\"}") == 0);
|
|
CHECK(gate(host, "webfetch", SP_AUTH_MUTATE,
|
|
"{\"url\":\"https://allowed.org/page\"}") == 0);
|
|
CHECK(gate(host, "run", SP_AUTH_DESTRUCTIVE,
|
|
"{\"command\":\"ls -la\"}") == 0);
|
|
|
|
sp_host_free(host);
|
|
sp_buf_free(&err);
|
|
snprintf(cmd, sizeof(cmd), "rm -rf '%s'", home);
|
|
(void)system(cmd);
|
|
if (failures == 0)
|
|
printf("test_kids: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|