| index c969c34..cee6ea5 100644 | ||
| --- a/README.md | ||
| +++ b/README.md | ||
| @@ -56,7 +56,7 @@ Content-Type: application/json; charset=utf-8 | ||
| 56 | 56 | Cache-Control: no-store |
| 57 | 57 | 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 | 60 | "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64", |
| 61 | 61 | "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"}, |
| 62 | 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 | 148 | ## Pre-built binaries |
| 149 | 149 | |
| 150 | 150 | 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 | 153 | | Target | File | |
| 154 | 154 | |---|---| |
| index 8aa7283..9a805b0 100755 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | |
| 29 | 29 | SLUG="hello" |
| 30 | 30 | ID="plugin_hello" |
| 31 | -VERSION="1.0.0" | |
| 31 | +VERSION="1.1.0" | |
| 32 | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | |
| 34 | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| index 20c426b..e369a72 100644 | ||
| --- a/src/plugin_hello.c | ||
| +++ b/src/plugin_hello.c | ||
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | |
| 35 | 35 | #define PLUGIN_SLUG "hello" |
| 36 | 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 | 40 | /* Query string helpers */ |
| @@ -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 | 245 | static int mode_meta(void) |
| 201 | 246 | { |
| 202 | 247 | puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}"); |
| @@ -467,6 +512,8 @@ int main(int argc, char **argv) | ||
| 467 | 512 | return 0; |
| 468 | 513 | } |
| 469 | 514 | |
| 515 | + require_node_auth(); | |
| 516 | + | |
| 470 | 517 | qs = getenv("QUERY_STRING"); |
| 471 | 518 | if (!qs) qs = ""; |
| 472 | 519 |
| index 2317298..5214139 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -62,9 +62,29 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 62 | 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | 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 | 67 | # ---------------------------------------------------------------- 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 | 88 | section "mode 2 JSON API" |
| 69 | 89 | INFO=$(QUERY_STRING='action=info' "$BIN") |
| 70 | 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 | 93 | check "info ok:true" '"ok":true' "$BODY" |
| 74 | 94 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 75 | 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 | 97 | check "info hostname field" '"hostname"' "$BODY" |
| 78 | 98 | check "info os field" '"os"' "$BODY" |
| 79 | 99 | check "info arch field" '"arch"' "$BODY" |
| 80 | 100 |
| index c969c34..cee6ea5 100644 | index 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-store | 56 | Cache-Control: no-store |
| 57 | X-Content-Type-Options: nosniff | 57 | 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 binaries | 148 | ## Pre-built binaries |
| 149 | 149 | ||
| 150 | If you would rather not compile, every release is published with checksums at | 150 | 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 | |---|---| |
| index 8aa7283..9a805b0 100755 | index 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)" |
| index 20c426b..e369a72 100644 | index 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 |
| index 2317298..5214139 100755 | index 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 mode | 67 | # ---------------------------------------------------------------- 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" |
| 80 | 100 |