Skip to content

Commit 5cbce97

Browse files
committed
security-audit: fix ownership check to respect protected file ownership
Protected files (bin/, hooks/, tool-guard.ts, security.mjs, etc.) are intentionally owned by bentlegen/root as an extra defense layer. The ownership check now excludes these paths instead of flagging them. Also exclude test files (*.test.sh, *.test.mjs) from the secret scan since they contain test fixtures with fake secret patterns.
1 parent 6456bf0 commit 5cbce97

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

bin/security-audit.sh

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,30 @@ if [ -d "$HORNET_HOME/.pi/session-control" ]; then
175175
fi
176176

177177
# Check for files owned by wrong user in hornet repo
178+
# NOTE: Protected files (bin/, hooks/, tool-guard.ts, security.mjs, etc.) are
179+
# intentionally owned by bentlegen/root as an extra defense layer. Only flag
180+
# unexpected non-hornet_agent ownership in agent-modifiable areas.
178181
if [ -d "$HORNET_HOME/hornet" ]; then
179-
wrong_owner=$(find "$HORNET_HOME/hornet" -not -user hornet_agent -not -path '*/.git/objects/*' 2>/dev/null | wc -l)
182+
wrong_owner=$(find "$HORNET_HOME/hornet" \
183+
-not -user hornet_agent \
184+
-not -path '*/.git/*' \
185+
-not -path '*/bin/*' \
186+
-not -path '*/hooks/*' \
187+
-not -path '*/.github/*' -not -path '*/.github' \
188+
-not -name '.secrets.baseline' \
189+
-not -path '*/tool-guard.ts' \
190+
-not -path '*/tool-guard.test.mjs' \
191+
-not -path '*/security.mjs' \
192+
-not -path '*/security.test.mjs' \
193+
-not -name 'setup.sh' \
194+
-not -name 'start.sh' \
195+
-not -name 'SECURITY.md' \
196+
2>/dev/null | wc -l)
180197
if [ "$wrong_owner" -gt 0 ]; then
181-
if fix_action "Fix $wrong_owner file(s) with wrong ownership" \
182-
find "$HORNET_HOME/hornet" -not -user hornet_agent -not -path '*/.git/objects/*' -exec chown hornet_agent:hornet_agent {} +; then
183-
ok "File ownership fixed in hornet repo"
184-
else
185-
finding "WARN" "$wrong_owner file(s) in hornet repo not owned by hornet_agent" \
186-
"Run: find ~/hornet -not -user hornet_agent -exec chown hornet_agent:hornet_agent {} +"
187-
fi
198+
finding "WARN" "$wrong_owner file(s) in hornet repo with unexpected ownership" \
199+
"Review with: find ~/hornet -not -user hornet_agent -not -path '*/bin/*' -not -path '*/.git/*'"
188200
else
189-
ok "All files in hornet repo owned by hornet_agent"
201+
ok "File ownership correct (protected files admin-owned, rest agent-owned)"
190202
fi
191203
fi
192204
echo ""
@@ -209,6 +221,8 @@ leaked_files=$(find "$HORNET_HOME" -maxdepth 3 \
209221
-not -name 'redact-logs.sh' \
210222
-not -name 'scan-extensions.mjs' \
211223
-not -name 'setup.sh' \
224+
-not -name '*.test.sh' \
225+
-not -name '*.test.mjs' \
212226
-type f -perm /044 \
213227
-exec grep -l -E "$secret_patterns" {} \; 2>/dev/null | head -5 || true)
214228

0 commit comments

Comments
 (0)