Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions client/harness/command_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,14 @@ def _outside_read_target(self, value: str) -> "tuple[str | None, str]":
return None, (f"{literal} contains the sandbox's own mounts "
f"and cannot be exposed — name a subdirectory.")

if not Path(literal).exists():
return None, ""
# A path the user may not even stat is refused with the reason, rather
# than raising out of the classifier and taking the session down.

try:
if not Path(literal).exists():
return None, ""
except OSError as exc:
return None, f"{literal} cannot be read here ({exc.strerror or exc})."

return literal, ""

Expand Down
15 changes: 15 additions & 0 deletions client/tests/test_command_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,21 @@ def test_an_input_redirection_reads_and_an_output_redirection_does_not(self):
writable = self.policy.classify(f"echo x > {self.outside}/memory.md")
self.assertEqual(writable.classification, CommandClassification.DANGEROUS)

def test_a_path_that_cannot_be_examined_is_refused_not_raised(self):
# A directory the user may not traverse made Path.exists raise, and
# the exception took the whole chat session down.
locked = self.outside / "locked"
locked.mkdir()
locked.chmod(0)

try:
assessment = self.policy.classify(f"ls -la {locked}/inside")
finally:
locked.chmod(0o700)

self.assertEqual(assessment.host_read_paths, ())
self.assertIn("cannot be read here", assessment.reason)

def test_a_missing_outside_path_binds_nothing_and_is_not_refused(self):
# ENOENT from the command is the truthful answer and the one the model
# can act on; a policy error about a file that was never there is not.
Expand Down
9 changes: 9 additions & 0 deletions scripts/docker/spear
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ backend() {
[ -n "$REDS_KEY" ] && SSH_OPTS+=(-o IdentitiesOnly=yes -i "$REDS_KEY")
echo "opening the tunnel :$LPORT -> $REDS_HOST:$REDS_PORT" >&2

# A tunnel that died with the VPN keeps its port, and a new one
# then fails to bind: say that, not "is the host reachable?".

if (exec 3<>"/dev/tcp/127.0.0.1/$LPORT") 2>/dev/null; then
held=$(ss -ltnpH "sport = :$LPORT" 2>/dev/null | grep -o 'pid=[0-9]*' | head -1)
WHY="port $LPORT is held by a tunnel that no longer answers${held:+ ($held)}: end it and run spear again"
return 1
fi

if ! ssh "${SSH_OPTS[@]}" -L "$LPORT:localhost:$REDS_PORT" -N -f "$REDS_HOST"; then
WHY="tunnel failed: is $REDS_HOST reachable (VPN?) and your key authorised?"
return 1
Expand Down
Loading