Repository navigation
pre-commit: refuse to commit this machine's hostname or public IP - #111
Conversation
The repository is public, and on this cloud box the hostname is the public IP address written with dashes, so any server id or launch record that carries the hostname publishes the address. #110 did that briefly. scripts/check_host_identity.sh looks for the hostname (when it is an address) and for every public IPv4 address `hostname -I` reports, dotted and dashed, in the staged files, and reports matches by file and line without repeating the value. The hook passes no filenames and reads the staged files itself, so the config's evidence/ exclusion does not hide evidence from it.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf93ca374a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if [ "$#" -gt 0 ]; then | ||
| files=("$@") | ||
| else | ||
| mapfile -t files < <(git diff --cached --name-only --diff-filter=ACMR) |
There was a problem hiding this comment.
Include type-changed files in the staged scan
When a tracked symlink is replaced by a regular file containing the machine address, Git classifies the staged entry as T (type changed), but --diff-filter=ACMR omits it. The resulting files array is empty and the hook succeeds even though the staged blob leaks the identity; include T in the filter. See Git's --diff-filter documentation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5621b86: the staged list is now read with git diff --cached --name-only -z --diff-filter=ACMRT into a NUL-delimited array, so quoted paths and type changes (a symlink replaced by a file) are both checked, and the staged blob is read with git cat-file blob. test_staged_unusual_paths_and_type_changes_are_checked covers both cases and fails on bf93ca3.
| if [ "$#" -gt 0 ]; then | ||
| files=("$@") | ||
| else | ||
| mapfile -t files < <(git diff --cached --name-only --diff-filter=ACMR) |
There was a problem hiding this comment.
Parse staged filenames with NUL delimiters
When a staged filename contains non-ASCII characters, tabs, newlines, or other characters Git quotes by default, this command stores the quoted representation rather than the actual path. The later file check therefore skips it, allowing an identity inside such a file to be committed; use Git's documented -z output with NUL-delimited mapfile parsing. See the -z documentation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5621b86: the staged list is now read with git diff --cached --name-only -z --diff-filter=ACMRT into a NUL-delimited array, so quoted paths and type changes (a symlink replaced by a file) are both checked, and the staged blob is read with git cat-file blob. test_staged_unusual_paths_and_type_changes_are_checked covers both cases and fails on bf93ca3.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Staged paths were read from git's default output, which quotes unusual names, so such a file was skipped. They are now read with -z. A symlink replaced by a regular file is staged as a type change (T), which the filter left out. Staged content is read with git cat-file, so a file deleted from the working tree after staging is still checked.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5621b86651
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for f in "${files[@]}"; do | ||
| # Staged content, not the working copy, when checking a commit. | ||
| if [ -n "$staged" ]; then | ||
| hits="$(git cat-file blob ":$f" 2>/dev/null | grep -n -I -F "${args[@]}" | cut -d: -f1 | tr '\n' ' ' || true)" |
There was a problem hiding this comment.
Scan binary blobs instead of excluding them
When a staged artifact contains any NUL byte—for example, a PDF or binary evidence file that embeds the hostname or address literally—grep -I treats the entire blob as having no matches, so this hook exits successfully and permits the identity leak it is meant to prevent. GNU grep's --help defines -I as equivalent to --binary-files=without-match; scan the blob as text (for example with -a) instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b8fe3b9. Both scans now use grep -a, so a blob with NUL bytes is searched as text instead of being treated as matching nothing. test_binary_files_are_scanned_too fails on 5621b86. The header notes that a compressed stream can still hide the address. 417b2ce also adds global IPv6 addresses as patterns.
|
Verdict: REQUEST CHANGES Review on the exact head 5621b86 (bf93ca3 and 5621b86). What I verified
Blocking
Suggestion (non-blocking). The address loop skips every IPv6 address ( |
grep -I treats any blob with a NUL byte as matching nothing, so a PDF or binary artifact that embeds the address passed. Scan with -a instead.
…treams Global IPv6 addresses from hostname -I are now patterns too (loopback, link-local and unique-local ones are skipped). The header notes that a compressed stream can still hide the address.
|
@codex review |
|
Verdict: APPROVE (provisional: Codex's review of 417b2ce was still running when I posted this. I will re-check its threads on this head before merge.) Re-review on the exact head 417b2ce (b8fe3b9 and 417b2ce on top of 5621b86).
Blocking: none. Suggestion (non-blocking). Link-local is |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 417b2ce199
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for p in "${patterns[@]}"; do args+=(-e "$p"); done | ||
|
|
||
| status=0 | ||
| for f in "${files[@]}"; do |
There was a problem hiding this comment.
Scan staged path names for host identity
In the no-argument pre-commit path, only each blob's contents are searched; the value of f itself is never checked. An artifact with clean contents but a name such as run-203-0-113-7.log therefore passes while still publishing the machine's hostname/address in the Git tree, so staged path names also need to be checked.
Useful? React with 👍 / 👎.
| for f in "${files[@]}"; do | ||
| # Staged content, not the working copy, when checking a commit. | ||
| if [ -n "$staged" ]; then | ||
| hits="$(git cat-file blob ":$f" 2>/dev/null | grep -n -a -F "${args[@]}" | cut -d: -f1 | tr '\n' ' ' || true)" |
There was a problem hiding this comment.
Match equivalent IPv6 text forms
On a host with a global IPv6 address containing hexadecimal letters, this fixed, case-sensitive search only catches the exact spelling emitted by hostname -I. A staged file can contain the same address with uppercase digits (for example, 2001:DB8::7 instead of 2001:db8::7) or an expanded zero representation and pass the hook, so IPv6 values must be compared using normalized or equivalent representations.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5652f31. For each global IPv6 address, the guard now builds both the compressed and the fully expanded spelling (Python's ipaddress), and the search ignores case. Other spellings, such as partly expanded zeros, are still not matched, and the header says so. test_ipv6_matches_any_case_and_the_expanded_form fails on 417b2ce. This box currently has no global IPv6 address.
… form A staged path that names the address was not checked, only contents. IPv6 addresses were matched only in the exact spelling hostname -I prints; the search now ignores case and also looks for the fully expanded form. Other spellings remain unmatched, as the header says.
|
@codex review |
|
Verdict: APPROVE (provisional: Codex's review of 5652f31 was still running when I posted this. I will re-check its threads on this head before merge.) Re-review on the exact head 5652f31. My provisional approval of 417b2ce did not stand: Codex left two P2s on that head, and this commit answers both.
Blocking: none. Suggestion (non-blocking, unchanged). The link-local glob still covers only |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5652f31fde
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # The path itself is published too. | ||
| for p in "${patterns[@]}"; do | ||
| if [[ ${f,,} == *"${p,,}"* ]]; then | ||
| echo "$f: the path contains this machine's hostname or IP address" >&2 |
There was a problem hiding this comment.
Redact identity-bearing paths from diagnostics
When the identity appears in a staged path, this diagnostic prints the complete path and therefore repeats the hostname or IP address that the hook explicitly promises not to report. This can expose the value in terminal captures or pre-commit/CI logs even though the commit is rejected; report a redacted path or a generic path-match message instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 41fdd4e. A path that contains the identity is now shown as "(a staged path, not shown)" in both the path message and the content message. test_paths_are_checked_as_well_as_contents now checks that stderr does not repeat the address, for a path with the dashed form and one with the dotted form.
The path diagnostic printed the full path, repeating the address it reports. A path that contains the identity is now shown as a placeholder in both the path and the content messages.
|
@codex review |
|
Verdict: APPROVE (provisional: Codex's review of 41fdd4e was still running when I posted this. I will re-check its threads on this head before merge.) Re-review on the exact head 41fdd4e ("check_host_identity: do not print a path that names the identity"). My provisional approval of 5652f31 did not stand, because Codex left a P2 on it.
Blocking: none. Suggestion (non-blocking). In explicit-file mode, the placeholder still says "a staged path". "(a path, not shown)" would fit both modes. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41fdd4e4f3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| hits="$(git cat-file blob ":$f" 2>/dev/null | grep -n -a -i -F "${args[@]}" | cut -d: -f1 | tr '\n' ' ' || true)" | ||
| else | ||
| [ -f "$f" ] || continue | ||
| hits="$(grep -n -a -i -F "${args[@]}" "$f" | cut -d: -f1 | tr '\n' ' ' || true)" |
There was a problem hiding this comment.
End grep option parsing before explicit filenames
When the advertised file-argument mode receives a basename beginning with -—for example, -v, including through the commit's suggested $(git ls-files) invocation—this operand is passed to grep without --. GNU grep's --help identifies -v as the --invert-match option; consequently, a file named -v containing the address is treated as an option, grep reads stdin instead, and the script returns success without scanning the file. Add -- before "$f".
Useful? React with 👍 / 👎.
| fi | ||
| for addr in $(hostname -I 2>/dev/null || true); do | ||
| case "$addr" in | ||
| ::1 | [fF][eE]80:* | [fF][cCdD]*:*) continue ;; # IPv6 loopback, link-local, unique local |
There was a problem hiding this comment.
Exclude the full IPv6 link-local range
When hostname -I returns a link-local address such as fe90::1, this case does not skip it because it recognizes only the fe80: spelling, while IPv6 link-local addresses occupy fe80::/10 (fe80 through febf). The address is therefore added as if it were global, and a file mentioning that non-public interface address is rejected contrary to the hook's documented behavior; classify the parsed address or cover the full prefix.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
|
Verdict: REQUEST CHANGES This updates my provisional approval of 41fdd4e (#111 (comment)), which I withdraw. Codex finished its review of 41fdd4e at 12:26:13 and left two P2s. Neither has a reply or fix yet, and both are sound and small. Blocking
Everything else from my 41fdd4e review still holds. |
…80::/10 A file named like an option (-v) was parsed by grep as one and not scanned; the file operand now follows --. Only the fe80: spelling of link-local IPv6 was skipped; addresses are now classified with Python's ipaddress, and only global ones become patterns.
|
@codex review |
|
Verdict: APPROVE (provisional: Codex's review of 68d1be3 was still running when I posted this. I will re-check its threads on this head before merge.) Re-review on the exact head 68d1be3 ("check_host_identity: end grep options before the file; skip all of fe80::/10").
Blocking: none. Suggestions: none. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68d1be30eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 127.* | 10.* | 192.168.* | 169.254.*) continue ;; | ||
| 172.1[6-9].* | 172.2[0-9].* | 172.3[01].*) continue ;; | ||
| esac | ||
| patterns+=("$addr" "${addr//./-}") |
There was a problem hiding this comment.
Classify IPv4 addresses before adding patterns
When hostname -I returns a non-global address outside the few ranges handled above, such as a CGNAT address in 100.64.0.0/10 or a benchmarking address in 198.18.0.0/15, this unconditional addition treats it as public and rejects any staged file mentioning it. This contradicts the hook's documented public-address scope and can block ordinary artifacts on hosts using those ranges; classify IPv4 values with ipaddress as is already done for IPv6.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4f9fe87. Every address from hostname -I is now classified with ipaddress.ip_address(...).is_global and becomes a pattern only if it is global (IPv4 dotted and dashed; IPv6 compressed and expanded). A dashed hostname follows the same rule. test_only_global_ipv4_addresses_are_patterns (with CGNAT 100.64.1.2, benchmarking 198.18.0.1 and private 10.0.0.2) and test_a_dashed_hostname_that_is_not_global_is_not_a_pattern both fail on 68d1be3. The tests' dashed-hostname examples moved off the documentation range, which is_global treats as non-global.
|
Verdict: REQUEST CHANGES This updates my provisional approval of 68d1be3 (#111 (comment)), which I withdraw. Codex finished its review of 68d1be3 at 12:29:37 and left one P2. It has no reply or fix yet. Blocking
Everything else from my 68d1be3 review still holds: the |
…ress Only RFC 1918, loopback and link-local IPv4 ranges were skipped, so CGNAT, benchmarking and other non-global addresses became patterns, against the hook's stated public scope. Every address from hostname -I, and a dashed hostname, is now a pattern only if ipaddress calls it global. The tests' dashed-hostname examples move from the documentation range, which is not global, to a public example address.
|
@codex review |
|
Verdict: APPROVE (provisional: Codex's review of 4f9fe87 was still running when I posted this. I will re-check its threads on this head before merge.) Re-review on the exact head 4f9fe87 ("check_host_identity: classify IPv4 and the dashed hostname with ipaddress").
Blocking: none. Suggestion (non-blocking). When |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verdict: APPROVE (confirmed on 4f9fe87) Codex finished its review of 4f9fe87 at 12:34:15 with "Didn't find any major issues". |
The repository is public, and on this cloud box the hostname is the public IP address written with dashes. Any server id or launch record that carries the hostname therefore publishes the address. #110 did that briefly (since fixed and force-pushed).
bench/server.pyalso records the hostname inlaunch.json, though no committed evidence carries it today.This adds a pre-commit hook,
forbid-host-identity, backed byscripts/check_host_identity.sh.hostname -Ireports (IPv4 dotted and dashed; IPv6 compressed and fully expanded, any case). Python'sipaddressdecides what is global, so private, CGNAT, link-local, unique-local and other reserved ranges are skipped. File paths are checked as well as contents, and a path that contains the identity is never printed.grep -a), so a PDF or binary artifact that embeds the address is caught. A compressed stream can still hide it, so generated archives need checking at the source.pass_filenames: falseandalways_run: true, so the config's top-levelevidence/exclusion does not hide evidence files from it. Given file arguments, it checks those files instead.The source changes that stop writing the hostname are in each workstream's own PR:
experiments/state_safety/server.pyin #110, andbench/server.pyin bench's next PR.Tests (
tests/test_check_host_identity.py, withhostnamefaked; the examples are a public address, 8.8.4.4, and 2600:1f18::/32, because the documentation ranges are not global):scripts/check_host_identity.sh $(git ls-files)passes on main's current tree.