Repository navigation
mono - chore: sync defense-in-depth files from agentic #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #!/usr/bin/env bash | ||
| # setup-cloud-environment.sh — Aikido Safe Chain bootstrap for Codespaces and Cursor Cloud Agents. | ||
| # setup-cloud-environment.sh — Aikido Safe Chain bootstrap for Codespaces, Cursor Cloud Agents, | ||
| # Claude Code on the web, and Codex cloud. | ||
| # | ||
| # Fail closed: never install dependencies unless Safe Chain shims are on PATH. | ||
| # Copied into the target repo as scripts/setup-cloud-environment.sh. | ||
|
|
@@ -12,6 +13,32 @@ SAFE_CHAIN_INSTALLER_URL="https://github.com/AikidoSec/safe-chain/releases/downl | |
| SAFE_CHAIN_SHIMS="${HOME}/.safe-chain/shims" | ||
| SAFE_CHAIN_BIN="${HOME}/.safe-chain/bin" | ||
|
|
||
| persist_shim_path() { | ||
| local rc="$1" | ||
| local line="export PATH=\"${SAFE_CHAIN_SHIMS}:${SAFE_CHAIN_BIN}:\$PATH\"" | ||
| if [[ -f "$rc" ]] && grep -Fqx -- "$line" "$rc"; then | ||
| return 0 | ||
| fi | ||
| mkdir -p "$(dirname "$rc")" | ||
| printf '\n# Aikido Safe Chain shims\n%s\n' "$line" >> "$rc" | ||
| } | ||
|
|
||
| # Claude Code starts each Bash command from a shell snapshot taken at launch, not the rc files, | ||
| # and runs CLAUDE_ENV_FILE before every command instead. A failed SessionStart hook does not stop | ||
| # the session, so the shims go on its PATH before anything here can fail, holding stubs that | ||
| # refuse to run until Safe Chain's setup-ci replaces them. | ||
| if [[ -n "${CLAUDE_ENV_FILE:-}" ]]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In Claude Code on the web, this block runs only if another hook starts the script. The target tree has no tracked AGENTS.md reference: AGENTS.md:L42-L50 Useful? React with 👍 / 👎. |
||
| mkdir -p "$SAFE_CHAIN_SHIMS" | ||
| for cmd in npm npx pnpm pnpx; do | ||
| if [[ ! -e "${SAFE_CHAIN_SHIMS}/${cmd}" ]]; then | ||
| printf '#!/bin/sh\necho "error: Safe Chain is not set up, so %s is blocked; run bash ./scripts/setup-cloud-environment.sh" >&2\nexit 1\n' \ | ||
| "$cmd" > "${SAFE_CHAIN_SHIMS}/${cmd}" | ||
|
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a prior Claude setup stops before Corepack creates pnpm, the next command sources the persisted shim path. Useful? React with 👍 / 👎. |
||
| chmod +x "${SAFE_CHAIN_SHIMS}/${cmd}" | ||
| fi | ||
| done | ||
| persist_shim_path "$CLAUDE_ENV_FILE" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Safe Chain 1.5.15 already exists from normal setup, the installer exits before it runs AGENTS.md reference: AGENTS.md:L42-L47 Useful? React with 👍 / 👎. |
||
| fi | ||
|
|
||
| if git_root=$(git rev-parse --show-toplevel 2>/dev/null); then | ||
| cd "$git_root" | ||
| fi | ||
|
|
@@ -50,16 +77,6 @@ echo "${SAFE_CHAIN_INSTALLER_SHA256} ${installer}" | sha256sum -c - | |
|
|
||
| export PATH="${SAFE_CHAIN_SHIMS}:${SAFE_CHAIN_BIN}:${PATH}" | ||
|
|
||
| persist_shim_path() { | ||
| local rc="$1" | ||
| local line="export PATH=\"${SAFE_CHAIN_SHIMS}:${SAFE_CHAIN_BIN}:\$PATH\"" | ||
| if [[ -f "$rc" ]] && grep -Fq ".safe-chain/shims" "$rc"; then | ||
| return 0 | ||
| fi | ||
| mkdir -p "$(dirname "$rc")" | ||
| printf '\n# Aikido Safe Chain shims\n%s\n' "$line" >> "$rc" | ||
| } | ||
|
|
||
| persist_shim_path "${HOME}/.profile" | ||
| persist_shim_path "${HOME}/.bashrc" | ||
| persist_shim_path "${HOME}/.zshrc" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using grep -Fqx with the exact expanded path ($line) is prone to false negatives. For example, if a developer uses $HOME or ~ instead of the absolute path (e.g., export PATH="$HOME/.safe-chain/shims..."), or if there are minor formatting differences (such as trailing comments or different quoting), grep -Fqx will fail to match and the script will repeatedly append duplicate export lines to the startup files (like .bashrc or .profile). Reverting to a more flexible check, such as checking for the presence of .safe-chain/shims in the file, prevents duplicate entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is a verbatim copy of
skills/security/defense-in-depth-nodejs/scripts/setup-cloud-environment.shatea156c03785398c8c156caa046ca954595f396c8. That revision replacedgrep -Fq ".safe-chain/shims"with the exact-line check atscripts/setup-cloud-environment.sh:19. A substring match treats any mention of.safe-chain/shimsas already configured, including a comment or a differentPATHorder. Changing it here would make this copy diverge from upstream again.