mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-28 03:02:38 +01:00
Yaak Proxy: dial the server before answering a CONNECT
The engine now opens the TCP connection to a CONNECT's server before it answers. When the server can't be reached, the CONNECT gets a 502 (or a 504 on a timeout) and the client reports its own connection error, rather than a 200 followed by a 502 inside the decrypted session or a silent hang-up in a tunnel. The failure is recorded as one error flow. The dialled connection is handed to the tunnel, or to the first upstream connection of a decrypted one, so nothing is dialled twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
649549482c
commit
ea288ec074
14 files changed
+889
-106
No files matched your search
@@ -3226,8 +3226,8 @@ const STOPPED_MID_STREAM: &str = "Yaak Proxy stopped before the stream ended";
|
||||
/// Why a tunnel still open when the engine stopped ended.
|
||||
const STOPPED_MID_TUNNEL: &str = "Yaak Proxy stopped before the connection closed";
|
||||
|
||||
/// Why a failed handshake's flow can't be saved as a request.
|
||||
pub(crate) const NOT_A_REQUEST: &str = "The TLS handshake failed before any request was sent";
|
||||
/// Why a failed handshake's or connection's flow can't be saved as a request.
|
||||
pub(crate) const NOT_A_REQUEST: &str = "The connection failed before any request was sent";
|
||||
|
||||
/// The error of a flow recording a client's refusal of the proxy's certificate.
|
||||
const REJECTED_CERTIFICATE: &str = "Certificate rejected by the app";
|
||||
@@ -3729,6 +3729,43 @@ impl FlowSink {
|
||||
graphql_scan: None,
|
||||
});
|
||||
}
|
||||
// No tunnel and no handshake: a failed connection, of the one event.
|
||||
ProxyEvent::ConnectFailed {
|
||||
id: _,
|
||||
started_at,
|
||||
authority,
|
||||
connection,
|
||||
client_addr,
|
||||
error,
|
||||
elapsed_ms,
|
||||
} => {
|
||||
if !recording.lock().map(|r| r.was_on_at(started_at)).unwrap_or(true) {
|
||||
return;
|
||||
}
|
||||
attribution.begin(connection, client_addr);
|
||||
let flow = Flow {
|
||||
id: Flow::generate_id(),
|
||||
started_at: DateTime::<Utc>::from(started_at).naive_utc(),
|
||||
url: format!("https://{authority}"),
|
||||
client_http_version: "HTTP/1.1".to_string(),
|
||||
client_addr: Some(client_addr.to_string()),
|
||||
elapsed_ms: Some(clamp_ms(elapsed_ms)),
|
||||
error: Some(error),
|
||||
..Default::default()
|
||||
};
|
||||
self.finish_flow(InFlight {
|
||||
flow,
|
||||
connection,
|
||||
request_body: None,
|
||||
response_body: None,
|
||||
persisted: false,
|
||||
cleared: false,
|
||||
next_seq: 0,
|
||||
dirty: false,
|
||||
last_write: None,
|
||||
graphql_scan: None,
|
||||
});
|
||||
}
|
||||
ProxyEvent::StreamStart { id, kind } => {
|
||||
if let Some(f) = in_flight.get_mut(&id) {
|
||||
let kind = StreamKind::from(kind);
|
||||
|
||||
@@ -229,7 +229,8 @@ impl Flow {
|
||||
}
|
||||
}
|
||||
|
||||
/// A client's failed TLS handshake, recorded without a request: nothing to save or replay.
|
||||
/// A client's failed TLS handshake, or a server that could not be reached, recorded without
|
||||
/// a request: nothing to save or replay.
|
||||
pub fn is_handshake_only(&self) -> bool {
|
||||
self.method.is_empty()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user