MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / attempt_gate_curl

Function attempt_gate_curl

examples/policy-advisor/ctf.py:182–214  ·  view source on GitHub ↗

Try to pass through a gate using curl as the binary. Returns the same tuple convention as ``attempt_gate``.

(gate: dict)

Source from the content-addressed store, hash-verified

180
181
182def attempt_gate_curl(gate: dict) -> tuple[str, str]:
183 """Try to pass through a gate using curl as the binary.
184
185 Returns the same tuple convention as ``attempt_gate``.
186 """
187 try:
188 result = subprocess.run(
189 ["curl", "-sS", "--max-time", "15", gate["url"]],
190 capture_output=True,
191 text=True,
192 timeout=20,
193 )
194 if result.returncode == 0 and result.stdout:
195 flag = gate["extract"](result.stdout)
196 return "pass", flag
197 stderr = result.stderr.strip().lower()
198 if any(tok in stderr for tok in ("403", "forbidden", "refused", "reset")):
199 return (
200 "blocked",
201 f"blocked by sandbox proxy (curl: {result.stderr.strip()[:80]})",
202 )
203 if result.returncode != 0:
204 return (
205 "blocked",
206 f"curl failed (rc={result.returncode}: {result.stderr.strip()[:80]})",
207 )
208 return "blocked", "curl returned empty response"
209 except subprocess.TimeoutExpired:
210 return "blocked", "curl timed out"
211 except FileNotFoundError:
212 return "error", "curl not found in sandbox"
213 except Exception as exc: # noqa: BLE001
214 return "error", f"unexpected curl error ({exc})"
215
216
217def attempt_gate(gate: dict) -> tuple[str, str]:

Callers 1

attempt_gateFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected