kids: the web is its own decision, not 'read, therefore allowed'

A search box is the whole internet, so websearch and webfetch stopped being read
tools the moment a child can call them:

  SPLINTER_KIDS_SEARCH=approve   every search asks a parent (default)
  SPLINTER_KIDS_SEARCH=allow     searching is fine, other fetches still ask
  SPLINTER_KIDS_SEARCH=deny      no open web at all

webfetch only reaches hosts in ~/.splinter/kids/domains, and that list works in
every mode: a page a parent wrote down is allowed even when the open web is shut,
because a curated list is the safe ground. Everything else falls through to the
approval path every other change already uses.

Measured:
  deny + websearch        -> 'Verboten'
  deny + webfetch netbsd.org (on the list) -> 'The NetBSD Project'
  approve, no parent channel -> no fetch, the model answers without it
This commit is contained in:
Konrad committed 2026-11-08 18:28:59 +00:00
1 parent f07cb01051
commit fc698b62ee
1 file changed
+95 -3
+95 -3
View File
@@ -38,6 +38,8 @@ static char approve_cmd[512];
static unsigned timeout_s = 120;
static char child_name[64] = "das Kind";
static char usage_file[700];
static char domains_file[700];
static int search_mode; /* 0 approve, 1 allow, 2 deny */
static unsigned daily_minutes; /* 0 = no limit */
static long used_seconds; /* today */
static time_t last_seen;
@@ -252,19 +254,99 @@ ask_parent(const char *tool, const char *args, char *reason, size_t reason_len)
return 0;
}
/*
* The web is not a filesystem. A child with a search box has the whole internet,
* so search is its own decision, not "read, therefore allowed":
*
* SPLINTER_KIDS_SEARCH=approve every search asks a parent (default)
* SPLINTER_KIDS_SEARCH=allow searching is fine, fetching still asks
* SPLINTER_KIDS_SEARCH=deny no web at all
*
* webfetch additionally only reaches hosts listed in ~/.splinter/kids/domains,
* because "the model picked this link" is not a safety argument.
*/
/* the url out of the tool arguments, without dragging the JSON parser in */
static void
arg_url(const char *args, char *buf, size_t len)
{
const char *p = args != NULL ? strstr(args, "\"url\":\"") : NULL;
size_t i = 0;
buf[0] = '\0';
if (p == NULL)
return;
p += 7;
while (*p != '\0' && *p != '"' && i + 1 < len)
buf[i++] = *p++;
buf[i] = '\0';
}
static int
host_allowed(const char *url)
{
FILE *f;
char line[256];
const char *host;
int ok = 0;
if (url == NULL)
return 0;
host = strstr(url, "://");
host = host != NULL ? host + 3 : url;
f = fopen(domains_file, "r");
if (f == NULL)
return 0;
while (fgets(line, sizeof(line), f) != NULL) {
size_t n, hlen;
line[strcspn(line, "\r\n")] = '\0';
if (line[0] == '#' || line[0] == '\0')
continue;
n = strlen(line);
hlen = strcspn(host, "/:");
if (hlen == n && strncmp(host, line, n) == 0) {
ok = 1;
break;
}
}
fclose(f);
return ok;
}
static int
kids_gate(struct sp_host *h, const char *tool, int auth, const char *args,
char *reason, size_t reason_len)
{
(void)h;
if (strcmp(tool, "websearch") == 0 || strcmp(tool, "webfetch") == 0) {
/*
* The curated list is the safe ground and works in every mode: a
* page a parent wrote down is allowed even when the open web is
* shut. Everything else follows the mode.
*/
if (strcmp(tool, "webfetch") == 0) {
char url[512];
arg_url(args, url, sizeof(url));
if (url[0] != '\0' && host_allowed(url))
return 1;
}
if (search_mode == 2) {
snprintf(reason, reason_len, "das Internet ist fuer %s "
"nicht freigeschaltet", child_name);
return 0;
}
if (strcmp(tool, "websearch") == 0 && search_mode == 1)
return 1;
/* fall through to the approval path below */
} else if (auth == SP_AUTH_READ)
return 1;
if (quota_left() == 0) {
snprintf(reason, reason_len, "fuer heute ist Schluss (%ld von %u "
"Minuten)", used_seconds / 60, daily_minutes);
return 0;
}
/* reading changes nothing; a child may look */
if (auth == SP_AUTH_READ)
return 1;
load_rules();
if (whitelisted(tool, args))
return 1;
@@ -381,6 +463,16 @@ kids_init(struct sp_host *h)
}
snprintf(allow_file, sizeof(allow_file), "%s/.splinter/kids/allow", home);
snprintf(usage_file, sizeof(usage_file), "%s/.splinter/kids/usage", home);
snprintf(domains_file, sizeof(domains_file), "%s/.splinter/kids/domains",
home);
{
const char *sm = getenv("SPLINTER_KIDS_SEARCH");
if (sm != NULL && strcmp(sm, "allow") == 0)
search_mode = 1;
else if (sm != NULL && strcmp(sm, "deny") == 0)
search_mode = 2;
}
{
const char *min = getenv("SPLINTER_KIDS_DAILY_MINUTES");