#!/usr/bin/env bash # CASAN shared log helper (source me, do not execute). # Taxonomy (shared with scripts/casan-log.mjs): error < warn < info < debug < trace. # CASAN_LOG_LEVEL selects the threshold (default: info). All log lines go to # stderr so stdout contracts (CASAN_HARNESS_COMPLETE, cache=..., evidence # .stdout files) stay byte-identical. casan_log_num() { case "$1" in error) echo 0 ;; warn) echo 1 ;; info) echo 2 ;; debug) echo 3 ;; trace) echo 4 ;; *) echo 2 ;; esac } CASAN_LOG_LEVEL="${CASAN_LOG_LEVEL:-info}" CASAN_LOG_THRESHOLD="$(casan_log_num "$CASAN_LOG_LEVEL")" # casan_log casan_log() { local lvl="$1" comp="$2" shift 2 [ "$(casan_log_num "$lvl")" -le "$CASAN_LOG_THRESHOLD" ] || return 0 # SEC-27 (X-02): log messages carry attacker-influenced data (action names, tool # output snippets). Strip control chars — ESC/CSI (terminal-escape injection that # rewrites a reviewer's screen) and CR/LF (fake-log-line injection) — keeping tab. local msg; msg="$(printf '%s' "$*" | tr -d '\000-\010\012-\037\177')" printf '[%s] %s [%s] %s\n' \ "$(printf '%s' "$lvl" | tr '[:lower:]' '[:upper:]')" \ "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ "$comp" "$msg" >&2 }