Files
zftpd/include/http_server.h
T
Seregon 8676fb32ec Harden HTTP/FTP security and path confinement
Add multiple security and robustness fixes across HTTP and FTP subsystems:

- HTTP API: introduce http_api_set_root/http_api_get_root and http_validate_and_confine to enforce filesystem confinement; validate and use canonical 'safe' paths in list/download/stats/create endpoints.
- HTTP server: accept a root_path on creation, store/propagate it to API, enforce upload confinement to the configured root, and switch connection counters and in-use flag to atomic types for thread-safety.
- CSRF: make http_csrf_init return int, fail hard if entropy is unavailable or conversion fails (disables uploads), track initialization with a flag and check it in validation; main logs when CSRF init fails.
- FTP: add static assert and safer logic in ftp_buffer_pool to prevent undefined behavior for large FTP_MAX_SESSIONS bitmasks; reformat buffer declaration and fix acquire/release logic.
- FTP commands: check snprintf truncation in MKD reply and add PORT IP validation against control connection (configurable via FTP_PORT_ALLOW_FOREIGN_IP).
- Build/test: update Makefile test target to build test_http_query using LIB_OBJECTS.

These changes close several path traversal, symlink, CSRF predictability, race/atomic and buffer-mask issues and improve overall robustness.
2026-03-02 02:00:55 +01:00

62 lines
2.0 KiB
C

/*
MIT License
Copyright (c) 2026 Seregon
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* @file http_server.h
* @brief HTTP server public API
*
* Usage:
* http_server_t *http = http_server_create(loop, 8888);
* // ... event loop runs ...
* http_server_destroy(http);
*/
#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H
#include "event_loop.h"
#include <stdint.h>
/* Opaque handle */
typedef struct http_server http_server_t;
/**
* @brief Create and start HTTP server on given port
*
* @param loop Event loop to register with
* @param port TCP port to listen on
* @param root_path Root directory for filesystem confinement
* (all HTTP file ops restricted to this subtree)
*
* @return Server handle, or NULL on failure
*/
http_server_t *http_server_create(event_loop_t *loop, uint16_t port,
const char *root_path);
/**
* @brief Stop and destroy HTTP server
*/
void http_server_destroy(http_server_t *server);
#endif /* HTTP_SERVER_H */