mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-18 18:32:28 +08:00
fix: random UUID installation_id + gitignore supabase/.temp
Replace SHA-256(hostname+user) with random UUID v4 stored in ~/.gstack/installation-id. Not derivable from public inputs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@ bun.lock
|
|||||||
.env.local
|
.env.local
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
supabase/.temp/
|
||||||
|
|||||||
@@ -106,18 +106,29 @@ if [ -d "$STATE_DIR/sessions" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate installation_id for community tier
|
# Generate installation_id for community tier
|
||||||
|
# Uses a random UUID stored locally — not derived from hostname/user so it
|
||||||
|
# can't be guessed or correlated by someone who knows your machine identity.
|
||||||
INSTALL_ID=""
|
INSTALL_ID=""
|
||||||
if [ "$TIER" = "community" ]; then
|
if [ "$TIER" = "community" ]; then
|
||||||
HOST="$(hostname 2>/dev/null || echo "unknown")"
|
ID_FILE="$HOME/.gstack/installation-id"
|
||||||
USER="$(whoami 2>/dev/null || echo "unknown")"
|
if [ -f "$ID_FILE" ]; then
|
||||||
if command -v shasum >/dev/null 2>&1; then
|
INSTALL_ID="$(cat "$ID_FILE" 2>/dev/null)"
|
||||||
INSTALL_ID="$(printf '%s-%s' "$HOST" "$USER" | shasum -a 256 | awk '{print $1}')"
|
fi
|
||||||
elif command -v sha256sum >/dev/null 2>&1; then
|
if [ -z "$INSTALL_ID" ]; then
|
||||||
INSTALL_ID="$(printf '%s-%s' "$HOST" "$USER" | sha256sum | awk '{print $1}')"
|
# Generate a random UUID v4
|
||||||
elif command -v openssl >/dev/null 2>&1; then
|
if command -v uuidgen >/dev/null 2>&1; then
|
||||||
INSTALL_ID="$(printf '%s-%s' "$HOST" "$USER" | openssl dgst -sha256 | awk '{print $NF}')"
|
INSTALL_ID="$(uuidgen | tr '[:upper:]' '[:lower:]')"
|
||||||
|
elif [ -r /proc/sys/kernel/random/uuid ]; then
|
||||||
|
INSTALL_ID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
|
else
|
||||||
|
# Fallback: random hex from /dev/urandom
|
||||||
|
INSTALL_ID="$(od -An -tx1 -N16 /dev/urandom 2>/dev/null | tr -d ' \n')"
|
||||||
|
fi
|
||||||
|
if [ -n "$INSTALL_ID" ]; then
|
||||||
|
mkdir -p "$(dirname "$ID_FILE")" 2>/dev/null
|
||||||
|
printf '%s' "$INSTALL_ID" > "$ID_FILE" 2>/dev/null
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
# If no SHA-256 command available, install_id stays empty
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Local-only fields (never sent remotely)
|
# Local-only fields (never sent remotely)
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ describe('gstack-telemetry-log', () => {
|
|||||||
|
|
||||||
const events = parseJsonl();
|
const events = parseJsonl();
|
||||||
expect(events).toHaveLength(1);
|
expect(events).toHaveLength(1);
|
||||||
// installation_id should be a SHA-256 hash (64 hex chars)
|
// installation_id should be a UUID v4 (or hex fallback)
|
||||||
expect(events[0].installation_id).toMatch(/^[a-f0-9]{64}$/);
|
expect(events[0].installation_id).toMatch(/^[a-f0-9-]{32,36}$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('installation_id is null for anonymous tier', () => {
|
test('installation_id is null for anonymous tier', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user