security: Make mobile listen on localhost by default.  I did not intend to leave it open.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Successful in 30m26s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Tilde Friends / Build-All (push) Successful in 30m26s
				
			This commit is contained in:
		| @@ -698,7 +698,7 @@ static void _http_on_connection(uv_stream_t* stream, int status) | ||||
| 	http->connections[http->connections_count++] = connection; | ||||
| } | ||||
|  | ||||
| int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data) | ||||
| int tf_http_listen(tf_http_t* http, int port, bool local_only, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data) | ||||
| { | ||||
| 	tf_http_listener_t* listener = tf_malloc(sizeof(tf_http_listener_t)); | ||||
| 	*listener = (tf_http_listener_t) { | ||||
| @@ -724,13 +724,13 @@ int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls, tf_http_cle | ||||
| 		*/ | ||||
| 		struct sockaddr_in addr = { | ||||
| 			.sin_family = AF_INET, | ||||
| 			.sin_addr = { .s_addr = INADDR_ANY }, | ||||
| 			.sin_addr = { .s_addr = local_only ? INADDR_LOOPBACK : INADDR_ANY }, | ||||
| 			.sin_port = ntohs(port), | ||||
| 		}; | ||||
| #else | ||||
| 		struct sockaddr_in6 addr = { | ||||
| 			.sin6_family = AF_INET6, | ||||
| 			.sin6_addr = IN6ADDR_ANY_INIT, | ||||
| 			.sin6_addr = local_only ? (struct in6_addr)IN6ADDR_LOOPBACK_INIT : (struct in6_addr)IN6ADDR_ANY_INIT, | ||||
| 			.sin6_port = ntohs(port), | ||||
| 		}; | ||||
| #endif | ||||
|   | ||||
| @@ -116,12 +116,13 @@ void tf_http_set_trace(tf_http_t* http, tf_trace_t* trace); | ||||
| ** times to listen on multiple ports. | ||||
| ** @param http The HTTP instance. | ||||
| ** @param port The port on which to listen, or 0 to assign a free port. | ||||
| ** @param local_only Only access connections on localhost, otherwise any address. | ||||
| ** @param tls An optional TLS context to use for HTTPS requests. | ||||
| ** @param cleanup A function called when the HTTP instance is being cleaned up. | ||||
| ** @param user_data User data passed to the cleanup callback. | ||||
| ** @return The port number on which the HTTP instance is now listening. | ||||
| */ | ||||
| int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data); | ||||
| int tf_http_listen(tf_http_t* http, int port, bool local_only, tf_tls_context_t* tls, tf_http_cleanup_t* cleanup, void* user_data); | ||||
|  | ||||
| /** | ||||
| ** Add an HTTP request handler. | ||||
|   | ||||
| @@ -2335,10 +2335,12 @@ void tf_httpd_register(JSContext* context) | ||||
| 	int64_t http_port = 0; | ||||
| 	int64_t https_port = 0; | ||||
| 	char out_http_port_file[512] = ""; | ||||
| 	bool local_only = false; | ||||
| 	sqlite3* db = tf_ssb_acquire_db_reader(ssb); | ||||
| 	tf_ssb_db_get_global_setting_int64(db, "http_port", &http_port); | ||||
| 	tf_ssb_db_get_global_setting_int64(db, "https_port", &https_port); | ||||
| 	tf_ssb_db_get_global_setting_string(db, "out_http_port_file", out_http_port_file, sizeof(out_http_port_file)); | ||||
| 	tf_ssb_db_get_global_setting_bool(db, "http_local_only", &local_only); | ||||
| 	tf_ssb_release_db_reader(ssb, db); | ||||
|  | ||||
| 	if (https_port) | ||||
| @@ -2400,7 +2402,7 @@ void tf_httpd_register(JSContext* context) | ||||
| 	{ | ||||
| 		httpd_listener_t* listener = tf_malloc(sizeof(httpd_listener_t)); | ||||
| 		*listener = (httpd_listener_t) { 0 }; | ||||
| 		int assigned_port = tf_http_listen(http, http_port, NULL, _httpd_listener_cleanup, listener); | ||||
| 		int assigned_port = tf_http_listen(http, http_port, local_only, NULL, _httpd_listener_cleanup, listener); | ||||
| 		tf_printf(CYAN "~😎 Tilde Friends" RESET " " YELLOW VERSION_NUMBER RESET " is now up at " MAGENTA "http://127.0.0.1:%d/" RESET ".\n", assigned_port); | ||||
|  | ||||
| 		if (*out_http_port_file) | ||||
| @@ -2433,7 +2435,7 @@ void tf_httpd_register(JSContext* context) | ||||
| 				tf_tls_context_set_private_key(tls, private_key); | ||||
| 				httpd_listener_t* listener = tf_malloc(sizeof(httpd_listener_t)); | ||||
| 				*listener = (httpd_listener_t) { .tls = tls }; | ||||
| 				int assigned_port = tf_http_listen(http, https_port, tls, _httpd_listener_cleanup, listener); | ||||
| 				int assigned_port = tf_http_listen(http, https_port, local_only, tls, _httpd_listener_cleanup, listener); | ||||
| 				tf_printf(CYAN "~😎 Tilde Friends" RESET " " YELLOW VERSION_NUMBER RESET " is now up at " MAGENTA "https://127.0.0.1:%d/" RESET ".\n", assigned_port); | ||||
| 			} | ||||
| 			tf_free((char*)certificate); | ||||
|   | ||||
| @@ -781,7 +781,7 @@ static void _test_http(const tf_test_options_t* options) | ||||
| 	tf_http_t* http = tf_http_create(&loop); | ||||
| 	tf_http_add_handler(http, "/hello", _test_http_handler, NULL, NULL); | ||||
| 	tf_http_add_handler(http, "/post", _test_http_handler_post, NULL, NULL); | ||||
| 	tf_http_listen(http, 23456, NULL, NULL, NULL); | ||||
| 	tf_http_listen(http, 23456, true, NULL, NULL, NULL); | ||||
|  | ||||
| 	test_http_t test = { .loop = &loop }; | ||||
| 	uv_async_init(&loop, &test.async, _test_http_async); | ||||
|   | ||||
| @@ -342,7 +342,8 @@ char* tf_trace_export(tf_trace_t* trace) | ||||
| 	size += snprintf(buffer, k_out_buffer_size, "{\"displayTimeUnit\": \"ns\",\n\"traceEvents\": [\n"); | ||||
| 	if (*trace->process_name) | ||||
| 	{ | ||||
| 		size += snprintf(buffer + size, k_out_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"name\":\"process_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(), trace->process_name); | ||||
| 		size += | ||||
| 			snprintf(buffer + size, k_out_buffer_size - size, "{\"ph\":\"M\",\"pid\":%d,\"name\":\"process_name\",\"args\":{\"name\":\"%s\"}},\n", getpid(), trace->process_name); | ||||
| 	} | ||||
| 	uv_rwlock_rdlock(&trace->threads_lock); | ||||
| 	for (int i = 0; i < trace->threads_count; i++) | ||||
|   | ||||
| @@ -345,6 +345,10 @@ static const setting_t k_settings[] = { | ||||
| 		.type = "integer", | ||||
| 		.description = "Port on which to listen for SSB secure handshake connections.", | ||||
| 		.default_value = { .kind = k_kind_int, .int_value = 8008 } }, | ||||
| 	{ .name = "http_local_only", | ||||
| 		.type = "boolean", | ||||
| 		.description = "Whether to bind http(s) to the loopback address.  Otherwise any.", | ||||
| 		.default_value = { .kind = k_kind_bool, .bool_value = TF_IS_MOBILE ? true : false } }, | ||||
| 	{ .name = "http_port", .type = "integer", .description = "Port on which to listen for HTTP connections.", .default_value = { .kind = k_kind_int, .int_value = 12345 } }, | ||||
| 	{ .name = "https_port", .type = "integer", .description = "Port on which to listen for secure HTTP connections.", .default_value = { .kind = k_kind_int, .int_value = 0 } }, | ||||
| 	{ .name = "out_http_port_file", .type = "hidden", .description = "File to which to write bound HTTP port.", .default_value = { .kind = k_kind_string, .string_value = NULL } }, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user