summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-08 12:28:48 +0100
committersalmonik <salmonik@tuta.io>2026-11-08 12:28:48 +0100
commit8681fcf565643f67a36cb1fe571fac7843d2b6af (patch)
tree1f022edb267281da0a2fd0fde3b5336293f14cea /src
parentweb: match the desktop layout and remove play-money copy (diff)
downloadzagan-bet-8681fcf565643f67a36cb1fe571fac7843d2b6af.tar.gz
zagan-bet-8681fcf565643f67a36cb1fe571fac7843d2b6af.zip
web: disallow crawlers and quiet the game port
Adds robots.txt with Disallow: / plus noindex/X-Robots-Tag on the site and app. The v5 server treats an HTTP request as a malformed frame, closes silently before HELLO, and suppresses the common TLS scanner noise. Deploy now verifies robots.txt.
Diffstat (limited to '')
-rw-r--r--src/bin/server/handler.rs21
-rw-r--r--src/bin/server/main.rs20
2 files changed, 37 insertions, 4 deletions
diff --git a/src/bin/server/handler.rs b/src/bin/server/handler.rs
index e6b623f..55df244 100644
--- a/src/bin/server/handler.rs
+++ b/src/bin/server/handler.rs
@@ -32,13 +32,19 @@ pub fn handle_client_tls(mut stream: TlsStream) {
32 32
33 let mut state = ConnectionState::default(); 33 let mut state = ConnectionState::default();
34 let mut event_seq = 0u64; 34 let mut event_seq = 0u64;
35 println!("[TLS Client connected] {client_addr}"); 35 // Port scanners reach the TLS listener too. Do not write a connection log
36 // until they send a valid frame; v5 drops their HTTP request silently.
37 let mut announced = false;
36 38
37 'connection: loop { 39 'connection: loop {
38 let mut frame = String::new(); 40 let mut frame = String::new();
39 match stream.read_frame(&mut frame) { 41 match stream.read_frame(&mut frame) {
40 Ok(0) => break, 42 Ok(0) => break,
41 Ok(_) => { 43 Ok(_) => {
44 if !announced {
45 println!("[TLS Client connected] {client_addr}");
46 announced = true;
47 }
42 let user = state.user().unwrap_or("guest").to_string(); 48 let user = state.user().unwrap_or("guest").to_string();
43 println!("[{user} @ {client_addr}] Received: {frame}"); 49 println!("[{user} @ {client_addr}] Received: {frame}");
44 match parse_request(&frame) { 50 match parse_request(&frame) {
@@ -70,6 +76,15 @@ pub fn handle_client_tls(mut stream: TlsStream) {
70 { 76 {
71 // No request yet: fall through and let timed games advance. 77 // No request yet: fall through and let timed games advance.
72 } 78 }
79 Err(error) if error.kind() == std::io::ErrorKind::InvalidData => {
80 // A crawler or port scanner speaking HTTP hits a frame length
81 // far over the cap. Close without a reply or a log line; a
82 // real game client that has already greeted is worth logging.
83 if state.greeted() {
84 eprintln!("Protocol error from {client_addr}: {error}");
85 }
86 break;
87 }
73 Err(error) => { 88 Err(error) => {
74 eprintln!("Read error: {error}"); 89 eprintln!("Read error: {error}");
75 break; 90 break;
@@ -92,5 +107,7 @@ pub fn handle_client_tls(mut stream: TlsStream) {
92 } 107 }
93 108
94 core.disconnect(&state); 109 core.disconnect(&state);
95 println!("[TLS Client disconnected] {client_addr}"); 110 if announced || state.greeted() {
111 println!("[TLS Client disconnected] {client_addr}");
112 }
96} 113}
diff --git a/src/bin/server/main.rs b/src/bin/server/main.rs
index f42574d..4f188a3 100644
--- a/src/bin/server/main.rs
+++ b/src/bin/server/main.rs
@@ -73,8 +73,24 @@ fn main() {
73 Ok(tls_stream) => { 73 Ok(tls_stream) => {
74 handler::handle_client_tls(tls_stream); 74 handler::handle_client_tls(tls_stream);
75 } 75 }
76 Err(e) => { 76 Err(error) => {
77 eprintln!("TLS handshake failed: {}", e); 77 // Public ports get a constant stream of scanners and resets.
78 // Keep the useful failures, drop the background noise.
79 let message = error.to_string().to_ascii_lowercase();
80 let noise = [
81 "unexpected eof",
82 "connection reset",
83 "broken pipe",
84 "handshake failure",
85 "received fatal alert",
86 "bad record mac",
87 "timed out",
88 ]
89 .iter()
90 .any(|needle| message.contains(needle));
91 if !noise {
92 eprintln!("TLS handshake failed: {error}");
93 }
78 } 94 }
79 }); 95 });
80 } 96 }