Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ endif
VENDOR_CFLAGS := $(filter-out -Werror,$(CFLAGS))
# TweetNaCl 20140427 (unmodified): sign-compare in FOR() and sigma[] string init on Clang/GCC -Wextra
# -Wunterminated-string-initialization exists on newer Clang/GCC only (not Ubuntu CI GCC 13).
TWEETNACL_WNO_UNTERM := $(shell $(CC) -Wno-error=unterminated-string-initialization -E -x c -o /dev/null /dev/null 2>&1 \
| grep -qE 'unrecognized|unknown option|no option' || echo -Wno-error=unterminated-string-initialization)
TWEETNACL_WNO_UNTERM := $(shell $(CC) -Werror -Wunterminated-string-initialization \
-fsyntax-only -x c /dev/null >/dev/null 2>&1 && echo -Wno-error=unterminated-string-initialization)
TWEETNACL_CFLAGS := $(CFLAGS) -Wno-error=sign-compare $(TWEETNACL_WNO_UNTERM) -fwrapv
# cJSON (vendored): cJSON_CreateNumber casts the double to int unconditionally, which is UB for
# NaN/Inf (NaN fails both saturation comparisons and falls into the plain (int)cast). ShellClaw's
Expand Down Expand Up @@ -834,12 +834,13 @@ test_hardware_on_device: shellclaw
@chmod +x tests/test_hardware_on_device.sh
@SHELLCLAW_TEST_BIN="$(BINDIR)/shellclaw" ./tests/test_hardware_on_device.sh

test_web_dashboard:
test_web_dashboard: $(if $(filter 1,$(GATEWAY)),src/gateway/ui_assets.h,)
@if [ "$${CI:-}" = "true" ] && ! command -v node >/dev/null 2>&1; then \
echo "test_web_dashboard: node required when CI=true" >&2; exit 1; \
fi
@if command -v node >/dev/null 2>&1; then node tests/test_web_dashboard.js; \
else echo "test_web_dashboard: skipped (node not installed)"; fi
@if [ "$(GATEWAY)" = "1" ] && command -v node >/dev/null 2>&1; then node tests/test_embedded_web.js; fi

# Mirrors .github/workflows/ci.yml AddressSanitizer job (CI=true GATEWAY=1).
# -fno-sanitize-recover=all + halt_on_error make any UBSan/ASan finding a hard
Expand Down
32 changes: 8 additions & 24 deletions scripts/embed_ui.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Embed Web UI assets: minify (optional), gzip, xxd -i -> src/gateway/ui_assets.h
# Embed Web UI assets: gzip, xxd -i -> src/gateway/ui_assets.h
# Input: web/index.html, web/hardware.html, web/css/style.css,
# web/js/dashboardView.js + web/js/app.js (concatenated),
# web/js/hardwareView.js (hardware page bundle)
Expand All @@ -15,42 +15,26 @@ OUT_HEADER="$PROJECT_ROOT/src/gateway/ui_assets.h"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT

# Optional minimal minify: collapse multiple spaces (safe for CSS/JS)
minify_sed() {
sed -e 's/[[:space:]]\+/ /g' \
-e 's/^[[:space:]]*//' \
-e 's/[[:space:]]*$//' \
"$@"
}

process_file() {
local src="$1"
local dst="$2"
local var_base="$3"
local var_base="$2"
if [ ! -f "$src" ]; then
echo "Error: $src not found" >&2
exit 1
fi
# Optional minimal minify for CSS/JS; HTML left as-is to avoid breaking structure
case "$src" in
*.html) cp "$src" "$TMP_DIR/$dst" ;;
*.css) minify_sed "$src" > "$TMP_DIR/$dst" ;;
*.js) minify_sed "$src" > "$TMP_DIR/$dst" ;;
*) cp "$src" "$TMP_DIR/$dst" ;;
esac
gzip -c -9 "$TMP_DIR/$dst" > "$TMP_DIR/${var_base}_gz.bin"
gzip -n -c -9 "$src" > "$TMP_DIR/${var_base}_gz.bin"
(cd "$TMP_DIR" && xxd -i "${var_base}_gz.bin") | \
sed "s/unsigned char ${var_base}_gz_bin/unsigned char ${var_base}_gz/" | \
sed "s/unsigned int ${var_base}_gz_bin_len/unsigned int ${var_base}_gz_len/"
}

mkdir -p "$(dirname "$OUT_HEADER")"
process_file "$WEB_DIR/index.html" "index.html" "ui_index_html" > "$TMP_DIR/index_html.txt"
process_file "$WEB_DIR/hardware.html" "hardware.html" "ui_hardware_html" > "$TMP_DIR/hardware_html.txt"
process_file "$WEB_DIR/css/style.css" "style.css" "ui_style_css" > "$TMP_DIR/style_css.txt"
process_file "$WEB_DIR/index.html" "ui_index_html" > "$TMP_DIR/index_html.txt"
process_file "$WEB_DIR/hardware.html" "ui_hardware_html" > "$TMP_DIR/hardware_html.txt"
process_file "$WEB_DIR/css/style.css" "ui_style_css" > "$TMP_DIR/style_css.txt"
cat "$WEB_DIR/js/dashboardView.js" "$WEB_DIR/js/app.js" > "$TMP_DIR/app_bundle.js"
process_file "$TMP_DIR/app_bundle.js" "app.js" "ui_app_js" > "$TMP_DIR/app_js.txt"
process_file "$WEB_DIR/js/hardwareView.js" "hardware.js" "ui_hardware_js" > "$TMP_DIR/hardware_js.txt"
process_file "$TMP_DIR/app_bundle.js" "ui_app_js" > "$TMP_DIR/app_js.txt"
process_file "$WEB_DIR/js/hardwareView.js" "ui_hardware_js" > "$TMP_DIR/hardware_js.txt"

# Compute total size and verify < 50 KB
TOTAL=0
Expand Down
3 changes: 3 additions & 0 deletions src/sandbox/allowlist_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ static int lexical_collapse_path(const char *path, char *out, size_t out_cap)
if (seg[0] == '\0' || strcmp(seg, ".") == 0)
continue;
if (strcmp(seg, "..") == 0) {
/* An unresolved relative parent has no known directory to cancel. */
if (!absolute && nparts == 0)
return -1;
if (nparts > 0) {
if (stacked_path_is_symlink(parts, nparts, absolute))
return -1;
Expand Down
16 changes: 16 additions & 0 deletions tests/test_allowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,24 @@ static int test_in_workspace_env_and_scanner_edges(void)
/* main */
/* ------------------------------------------------------------------ */

static int test_relative_file_uses_working_directory(void)
{
char workspace[] = "/tmp/shellclaw-relative-path-XXXXXX";
char previous[PATH_MAX];
ASSERT(getcwd(previous, sizeof(previous)) != NULL);
ASSERT(mkdtemp(workspace) != NULL);
ASSERT(allowlist_path_is_under_workspace("new-note.txt", workspace) == 0);
ASSERT(chdir(workspace) == 0);
int inside = allowlist_path_is_under_workspace("new-note.txt", workspace);
ASSERT(chdir(previous) == 0);
ASSERT(rmdir(workspace) == 0);
ASSERT(inside == 1);
return 0;
}

int main(void)
{
RUN(test_relative_file_uses_working_directory());
RUN(test_block_rm_rf_root());
RUN(test_block_rm_rf_wildcard());
RUN(test_block_mkfs());
Expand Down
25 changes: 25 additions & 0 deletions tests/test_embedded_web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const zlib = require('node:zlib');

const root = path.join(__dirname, '..');
const header = fs.readFileSync(path.join(root, 'src/gateway/ui_assets.h'), 'utf8');
for (const [asset, sources] of [
['ui_app_js_gz', ['dashboardView.js', 'app.js']],
['ui_hardware_js_gz', ['hardwareView.js']],
]) {
const match = header.match(new RegExp(asset + '\\[\\]\\s*=\\s*\\{([^}]+)\\}'));
assert.ok(match, 'Missing asset ' + asset);
const bytes = Buffer.from(match[1].match(/0x[\da-f]{2}/gi).map(byte => Number(byte)));
const script = zlib.gunzipSync(bytes).toString('utf8');
new vm.Script(script, { filename: asset });
for (const source of sources) {
const original = fs.readFileSync(path.join(root, 'web/js', source), 'utf8');
assert.ok(script.includes(original), 'Changed source text in ' + source);
}
}
console.log('Both embedded JavaScript files passed.');
Loading