fix(auth): require the node password before serving any mode (v1.1.0)
Found while re-auditing plugin_docker against the required-skill contracts: the node API on :8150 is LAN-reachable and this plugin answered every request without credentials (live check returned 200 with no password). The reference plugin was the worst possible place for that hole, since every future plugin is copied from it. require_node_auth() accepts X-Bot-Password, Authorization: Bearer or ?pwd= and is a no-op only when BOT_PASSWORD is unset, matching terminal_tmux.c and node_rdp.c. --meta still works unauthenticated. Nine new assertions; 92 total, all passing. Bumped to 1.1.0.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 02:10:03
Commitb81ae322
Parentse2d45950
Changed files
README.md+2−2■■■■
release-dist.sh+1−1■■
src/plugin_hello.c+49−2■■■■■
tests/run.sh+22−2■■■■■
4 files+74−7
Diff
README.md+2−2■■■■
index c969c34..cee6ea5 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@ Content-Type: application/json; charset=utf-8
5656 Cache-Control: no-store
5757 X-Content-Type-Options: nosniff
5858
59-{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.0.0",
59+{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.1.0",
6060 "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64",
6161 "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"},
6262 "query_string":"action=info",
@@ -148,7 +148,7 @@ curl -s -H "X-Bot-Password: <pwd>" http://127.0.0.1:8150/plugins | grep hello
148148 ## Pre-built binaries
149149
150150 If you would rather not compile, every release is published with checksums at
151-**https://dist.scorpiox.net/bot-plugins/hello/1.0.0/**
151+**https://dist.scorpiox.net/bot-plugins/hello/1.1.0/**
152152
153153 | Target | File |
154154 |---|---|
release-dist.sh+1−1■■
index 8aa7283..9a805b0 100755
--- a/release-dist.sh
+++ b/release-dist.sh
@@ -28,7 +28,7 @@ set -euo pipefail
2828
2929 SLUG="hello"
3030 ID="plugin_hello"
31-VERSION="1.0.0"
31+VERSION="1.1.0"
3232 DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"
3333
3434 ROOT="$(cd "$(dirname "$0")" && pwd)"
src/plugin_hello.c+49−2■■■■■
index 20c426b..e369a72 100644
--- a/src/plugin_hello.c
+++ b/src/plugin_hello.c
@@ -34,7 +34,7 @@
3434
3535 #define PLUGIN_SLUG "hello"
3636 #define PLUGIN_ID "plugin_hello"
37-#define PLUGIN_VER "1.0.0"
37+#define PLUGIN_VER "1.1.0"
3838
3939 /* ------------------------------------------------------------------ */
4040 /* Query string helpers */
@@ -194,9 +194,54 @@ static void utc_now(char *buf, size_t sz)
194194 }
195195
196196 /* ------------------------------------------------------------------ */
197-/* Modes */
197+/* Node auth */
198198 /* ------------------------------------------------------------------ */
199199
200+/*
201+ * The node API (:8150) is reachable from the LAN, so a plugin must not answer
202+ * an unauthenticated caller. Accepted forms match the rest of the node API:
203+ * X-Bot-Password, Authorization: Bearer, or ?pwd=. When BOT_PASSWORD is unset
204+ * the node is in explicitly open mode and this is a no-op, exactly like
205+ * terminal_tmux.c and node_rdp.c.
206+ */
207+static void require_node_auth(void)
208+{
209+ const char *np = getenv("BOT_PASSWORD");
210+ const char *xp;
211+ const char *auth;
212+ const char *qs;
213+ char qpwd[256];
214+
215+ if (!np || !*np) return;
216+
217+ xp = getenv("HTTP_X_BOT_PASSWORD");
218+ if (xp && strcmp(xp, np) == 0) return;
219+
220+ auth = getenv("HTTP_AUTHORIZATION");
221+ if (auth) {
222+ while (*auth == ' ') auth++;
223+ if (strncmp(auth, "Bearer ", 7) == 0) {
224+ auth += 7;
225+ while (*auth == ' ') auth++;
226+ if (strcmp(auth, np) == 0) return;
227+ }
228+ }
229+
230+ qs = getenv("QUERY_STRING");
231+ if (qs && get_query_val(qs, "pwd", qpwd, sizeof(qpwd)) && strcmp(qpwd, np) == 0)
232+ return;
233+
234+ fputs("Status: 401 Unauthorized\r\n"
235+ "Content-Type: application/json; charset=utf-8\r\n"
236+ "Cache-Control: no-store\r\n"
237+ "X-Content-Type-Options: nosniff\r\n\r\n"
238+ "{\"ok\":false,\"error\":\"invalid node password\"}\n", stdout);
239+ exit(0);
240+}
241+
242+/* ------------------------------------------------------------------ */
243+/* Modes */
244+/* ------------------------------------------------------------------ */
200245 static int mode_meta(void)
201246 {
202247 puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}");
@@ -467,6 +512,8 @@ int main(int argc, char **argv)
467512 return 0;
468513 }
469514
515+ require_node_auth();
516+
470517 qs = getenv("QUERY_STRING");
471518 if (!qs) qs = "";
472519
tests/run.sh+22−2■■■■■
index 2317298..5214139 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -62,9 +62,29 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/')
6262 [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
6363 NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/')
6464 [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"
65-check "--version prints version" '1.0.0' "$("$BIN" --version)"
65+check "--version prints version" '1.1.0' "$("$BIN" --version)"
6666
6767 # ---------------------------------------------------------------- json mode
68+section "node auth"
69+authbody() { printf '%s' "$1" | sed '1,/^\r$/d'; }
70+AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN")
71+check "no credentials -> 401" 'Status: 401' "$AUTHNONE"
72+check "401 body is json error" 'invalid node password' "$AUTHNONE"
73+AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=info' "$BIN")
74+check "wrong header password -> 401" 'Status: 401' "$AUTHBAD"
75+AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN")
76+check "X-Bot-Password accepted" '"ok":true' "$(authbody "$AUTHHDR")"
77+AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=info' "$BIN")
78+check "Authorization Bearer accepted" '"ok":true' "$(authbody "$AUTHBEAR")"
79+AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=info&pwd=testpw' "$BIN")
80+check "?pwd= accepted" '"ok":true' "$(authbody "$AUTHQ")"
81+AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN")
82+check "html page requires auth too" 'Status: 401' "$AUTHHTML"
83+AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta)
84+check "--meta succeeds without auth" '"name":"hello"' "$AUTHMETA"
85+AUTHOPEN=$(QUERY_STRING='action=info' "$BIN")
86+check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN"
87+
6888 section "mode 2 JSON API"
6989 INFO=$(QUERY_STRING='action=info' "$BIN")
7090 check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO"
@@ -73,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d')
7393 check "info ok:true" '"ok":true' "$BODY"
7494 check "info plugin id" '"plugin":"plugin_hello"' "$BODY"
7595 check "info slug" '"slug":"hello"' "$BODY"
76-check "info version" '"version":"1.0.0"' "$BODY"
96+check "info version" '"version":"1.1.0"' "$BODY"
7797 check "info hostname field" '"hostname"' "$BODY"
7898 check "info os field" '"os"' "$BODY"
7999 check "info arch field" '"arch"' "$BODY"
80100
README.md+2−2■■■■
index c969c34..cee6ea5 100644index c969c34..cee6ea5 100644
--- a/README.md--- a/README.md
+++ b/README.md+++ b/README.md
@@ -56,7 +56,7 @@ Content-Type: application/json; charset=utf-8@@ -56,7 +56,7 @@ Content-Type: application/json; charset=utf-8
56 Cache-Control: no-store56 Cache-Control: no-store
57 X-Content-Type-Options: nosniff57 X-Content-Type-Options: nosniff
58 58
59-{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.0.0",59+{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.1.0",
60 "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64",60 "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64",
61 "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"},61 "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"},
62 "query_string":"action=info",62 "query_string":"action=info",
@@ -148,7 +148,7 @@ curl -s -H "X-Bot-Password: <pwd>" http://127.0.0.1:8150/plugins | grep hello@@ -148,7 +148,7 @@ curl -s -H "X-Bot-Password: <pwd>" http://127.0.0.1:8150/plugins | grep hello
148 ## Pre-built binaries148 ## Pre-built binaries
149 149
150 If you would rather not compile, every release is published with checksums at150 If you would rather not compile, every release is published with checksums at
151-**https://dist.scorpiox.net/bot-plugins/hello/1.0.0/**151+**https://dist.scorpiox.net/bot-plugins/hello/1.1.0/**
152 152
153 | Target | File |153 | Target | File |
154 |---|---|154 |---|---|
release-dist.sh+1−1■■
index 8aa7283..9a805b0 100755index 8aa7283..9a805b0 100755
--- a/release-dist.sh--- a/release-dist.sh
+++ b/release-dist.sh+++ b/release-dist.sh
@@ -28,7 +28,7 @@ set -euo pipefail@@ -28,7 +28,7 @@ set -euo pipefail
28 28
29 SLUG="hello"29 SLUG="hello"
30 ID="plugin_hello"30 ID="plugin_hello"
31-VERSION="1.0.0"31+VERSION="1.1.0"
32 DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"32 DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"
33 33
34 ROOT="$(cd "$(dirname "$0")" && pwd)"34 ROOT="$(cd "$(dirname "$0")" && pwd)"
src/plugin_hello.c+49−2■■■■■
index 20c426b..e369a72 100644index 20c426b..e369a72 100644
--- a/src/plugin_hello.c--- a/src/plugin_hello.c
+++ b/src/plugin_hello.c+++ b/src/plugin_hello.c
@@ -34,7 +34,7 @@@@ -34,7 +34,7 @@
34 34
35 #define PLUGIN_SLUG "hello"35 #define PLUGIN_SLUG "hello"
36 #define PLUGIN_ID "plugin_hello"36 #define PLUGIN_ID "plugin_hello"
37-#define PLUGIN_VER "1.0.0"37+#define PLUGIN_VER "1.1.0"
38 38
39 /* ------------------------------------------------------------------ */39 /* ------------------------------------------------------------------ */
40 /* Query string helpers */40 /* Query string helpers */
@@ -194,9 +194,54 @@ static void utc_now(char *buf, size_t sz)@@ -194,9 +194,54 @@ static void utc_now(char *buf, size_t sz)
194 }194 }
195 195
196 /* ------------------------------------------------------------------ */196 /* ------------------------------------------------------------------ */
197-/* Modes */197+/* Node auth */
198 /* ------------------------------------------------------------------ */198 /* ------------------------------------------------------------------ */
199 199
200+/*
201+ * The node API (:8150) is reachable from the LAN, so a plugin must not answer
202+ * an unauthenticated caller. Accepted forms match the rest of the node API:
203+ * X-Bot-Password, Authorization: Bearer, or ?pwd=. When BOT_PASSWORD is unset
204+ * the node is in explicitly open mode and this is a no-op, exactly like
205+ * terminal_tmux.c and node_rdp.c.
206+ */
207+static void require_node_auth(void)
208+{
209+ const char *np = getenv("BOT_PASSWORD");
210+ const char *xp;
211+ const char *auth;
212+ const char *qs;
213+ char qpwd[256];
214+
215+ if (!np || !*np) return;
216+
217+ xp = getenv("HTTP_X_BOT_PASSWORD");
218+ if (xp && strcmp(xp, np) == 0) return;
219+
220+ auth = getenv("HTTP_AUTHORIZATION");
221+ if (auth) {
222+ while (*auth == ' ') auth++;
223+ if (strncmp(auth, "Bearer ", 7) == 0) {
224+ auth += 7;
225+ while (*auth == ' ') auth++;
226+ if (strcmp(auth, np) == 0) return;
227+ }
228+ }
229+
230+ qs = getenv("QUERY_STRING");
231+ if (qs && get_query_val(qs, "pwd", qpwd, sizeof(qpwd)) && strcmp(qpwd, np) == 0)
232+ return;
233+
234+ fputs("Status: 401 Unauthorized\r\n"
235+ "Content-Type: application/json; charset=utf-8\r\n"
236+ "Cache-Control: no-store\r\n"
237+ "X-Content-Type-Options: nosniff\r\n\r\n"
238+ "{\"ok\":false,\"error\":\"invalid node password\"}\n", stdout);
239+ exit(0);
240+}
241+
242+/* ------------------------------------------------------------------ */
243+/* Modes */
244+/* ------------------------------------------------------------------ */
200 static int mode_meta(void)245 static int mode_meta(void)
201 {246 {
202 puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}");247 puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}");
@@ -467,6 +512,8 @@ int main(int argc, char **argv)@@ -467,6 +512,8 @@ int main(int argc, char **argv)
467 return 0;512 return 0;
468 }513 }
469 514
515+ require_node_auth();
516+
470 qs = getenv("QUERY_STRING");517 qs = getenv("QUERY_STRING");
471 if (!qs) qs = "";518 if (!qs) qs = "";
472 519
tests/run.sh+22−2■■■■■
index 2317298..5214139 100755index 2317298..5214139 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -62,9 +62,29 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/')@@ -62,9 +62,29 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/')
62 [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"62 [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
63 NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/')63 NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/')
64 [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"64 [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"
65-check "--version prints version" '1.0.0' "$("$BIN" --version)"65+check "--version prints version" '1.1.0' "$("$BIN" --version)"
66 66
67 # ---------------------------------------------------------------- json mode67 # ---------------------------------------------------------------- json mode
68+section "node auth"
69+authbody() { printf '%s' "$1" | sed '1,/^\r$/d'; }
70+AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN")
71+check "no credentials -> 401" 'Status: 401' "$AUTHNONE"
72+check "401 body is json error" 'invalid node password' "$AUTHNONE"
73+AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=info' "$BIN")
74+check "wrong header password -> 401" 'Status: 401' "$AUTHBAD"
75+AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=info' "$BIN")
76+check "X-Bot-Password accepted" '"ok":true' "$(authbody "$AUTHHDR")"
77+AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=info' "$BIN")
78+check "Authorization Bearer accepted" '"ok":true' "$(authbody "$AUTHBEAR")"
79+AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=info&pwd=testpw' "$BIN")
80+check "?pwd= accepted" '"ok":true' "$(authbody "$AUTHQ")"
81+AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN")
82+check "html page requires auth too" 'Status: 401' "$AUTHHTML"
83+AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta)
84+check "--meta succeeds without auth" '"name":"hello"' "$AUTHMETA"
85+AUTHOPEN=$(QUERY_STRING='action=info' "$BIN")
86+check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN"
87+
68 section "mode 2 JSON API"88 section "mode 2 JSON API"
69 INFO=$(QUERY_STRING='action=info' "$BIN")89 INFO=$(QUERY_STRING='action=info' "$BIN")
70 check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO"90 check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO"
@@ -73,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d')@@ -73,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d')
73 check "info ok:true" '"ok":true' "$BODY"93 check "info ok:true" '"ok":true' "$BODY"
74 check "info plugin id" '"plugin":"plugin_hello"' "$BODY"94 check "info plugin id" '"plugin":"plugin_hello"' "$BODY"
75 check "info slug" '"slug":"hello"' "$BODY"95 check "info slug" '"slug":"hello"' "$BODY"
76-check "info version" '"version":"1.0.0"' "$BODY"96+check "info version" '"version":"1.1.0"' "$BODY"
77 check "info hostname field" '"hostname"' "$BODY"97 check "info hostname field" '"hostname"' "$BODY"
78 check "info os field" '"os"' "$BODY"98 check "info os field" '"os"' "$BODY"
79 check "info arch field" '"arch"' "$BODY"99 check "info arch field" '"arch"' "$BODY"
80100