Skip to content

Commit 8e8977f

Browse files
CrazyBoyMclaude
andcommitted
Phase 4: review fixes - multi-provider, timing-safe auth, data-driven models, compat
- Added Google Gemini and OpenRouter/OpenAI-compatible provider support - Data-driven model catalog (lib/models.json) replacing hardcoded case statements - Model aliases (fast, smart, balanced, cheap, etc.) - Timing-safe secret comparison for pairing code verification - Secure pairing code generation via /dev/urandom - Expanded config schema validation (12+ checks) - Structured session key format matching OpenClaw pattern - Fixed local outside function scope in http_handler.sh - chmod 600 Termux fallback across 9 files - Reduced jq subprocess spawning via batching - POSIX-compliant sleep values Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ef77746 commit 8e8977f

File tree

19 files changed

+809
-101
lines changed

19 files changed

+809
-101
lines changed

gateway/http_handler.sh

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if ! declare -f log_info &>/dev/null; then
1414
source "${SCRIPT_DIR}/lib/routing.sh"
1515

1616
# Load .env if present
17-
local env_file="${BASHCLAW_STATE_DIR:?}/.env"
17+
env_file="${BASHCLAW_STATE_DIR:?}/.env"
1818
if [[ -f "$env_file" ]]; then
1919
set -a
2020
source "$env_file"
@@ -183,11 +183,22 @@ _handle_chat() {
183183
return
184184
fi
185185

186+
# Parse all fields from body in a single jq call
187+
local parsed
188+
parsed="$(printf '%s' "$HTTP_BODY" | jq -r '[
189+
(.message // ""),
190+
(.agent // "main"),
191+
(.channel // "web"),
192+
(.sender // "http")
193+
] | join("\n")' 2>/dev/null)"
194+
186195
local message agent_id channel sender
187-
message="$(printf '%s' "$HTTP_BODY" | jq -r '.message // empty' 2>/dev/null)"
188-
agent_id="$(printf '%s' "$HTTP_BODY" | jq -r '.agent // "main"' 2>/dev/null)"
189-
channel="$(printf '%s' "$HTTP_BODY" | jq -r '.channel // "web"' 2>/dev/null)"
190-
sender="$(printf '%s' "$HTTP_BODY" | jq -r '.sender // "http"' 2>/dev/null)"
196+
{
197+
IFS= read -r message
198+
IFS= read -r agent_id
199+
IFS= read -r channel
200+
IFS= read -r sender
201+
} <<< "$parsed"
191202

192203
if [[ -z "$message" ]]; then
193204
_http_respond_json 400 '{"error":"message field is required"}'
@@ -210,15 +221,23 @@ _handle_chat() {
210221
_handle_session_clear() {
211222
require_command jq "session clear handler requires jq"
212223

213-
local agent_id channel sender
224+
local agent_id="main"
225+
local channel="web"
226+
local sender="http"
227+
214228
if [[ -n "$HTTP_BODY" ]]; then
215-
agent_id="$(printf '%s' "$HTTP_BODY" | jq -r '.agent // "main"' 2>/dev/null)"
216-
channel="$(printf '%s' "$HTTP_BODY" | jq -r '.channel // "web"' 2>/dev/null)"
217-
sender="$(printf '%s' "$HTTP_BODY" | jq -r '.sender // "http"' 2>/dev/null)"
218-
else
219-
agent_id="main"
220-
channel="web"
221-
sender="http"
229+
local parsed
230+
parsed="$(printf '%s' "$HTTP_BODY" | jq -r '[
231+
(.agent // "main"),
232+
(.channel // "web"),
233+
(.sender // "http")
234+
] | join("\n")' 2>/dev/null)"
235+
236+
{
237+
IFS= read -r agent_id
238+
IFS= read -r channel
239+
IFS= read -r sender
240+
} <<< "$parsed"
222241
fi
223242

224243
local sess_file
@@ -236,10 +255,19 @@ _handle_message_send() {
236255
return
237256
fi
238257

258+
local parsed
259+
parsed="$(printf '%s' "$HTTP_BODY" | jq -r '[
260+
(.channel // ""),
261+
(.target // ""),
262+
(.message // "")
263+
] | join("\n")' 2>/dev/null)"
264+
239265
local ch target text
240-
ch="$(printf '%s' "$HTTP_BODY" | jq -r '.channel // empty' 2>/dev/null)"
241-
target="$(printf '%s' "$HTTP_BODY" | jq -r '.target // empty' 2>/dev/null)"
242-
text="$(printf '%s' "$HTTP_BODY" | jq -r '.message // empty' 2>/dev/null)"
266+
{
267+
IFS= read -r ch
268+
IFS= read -r target
269+
IFS= read -r text
270+
} <<< "$parsed"
243271

244272
if [[ -z "$ch" || -z "$target" || -z "$text" ]]; then
245273
_http_respond_json 400 '{"error":"channel, target, and message are required"}'

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ _create_default_config() {
311311
}
312312
CONFIGEOF
313313

314-
chmod 600 "$config_file"
314+
chmod 600 "$config_file" 2>/dev/null || true
315315
_info "Created default config: $config_file"
316316
}
317317

0 commit comments

Comments
 (0)