diff --git a/src/config/config.c b/src/config/config.c index a2295a286..0d33b6bd0 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -1061,7 +1061,7 @@ static void initConfig(struct config *conf) conf->webserver.paths.webhome.t = CONF_STRING; conf->webserver.paths.webhome.f = FLAG_RESTART_FTL; conf->webserver.paths.webhome.d.s = (char*)"/admin/"; - conf->webserver.paths.webhome.c = validate_filepath; + conf->webserver.paths.webhome.c = validate_filepath_two_slash; // sub-struct interface conf->webserver.interface.boxed.k = "webserver.interface.boxed"; diff --git a/src/config/validator.c b/src/config/validator.c index d6a8983e6..450b30692 100644 --- a/src/config/validator.c +++ b/src/config/validator.c @@ -270,6 +270,21 @@ bool validate_filepath(union conf_value *val, const char *key, char err[VALIDATO return true; } +// Validate a file path that needs to have both a slash at the beginning and at +// the end +bool validate_filepath_two_slash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]) +{ + // Check if the path starts and ends with a slash + if(strlen(val->s) < 1 || val->s[0] != '/' || val->s[strlen(val->s) - 1] != '/') + { + snprintf(err, VALIDATOR_ERRBUF_LEN, "%s: file path does not start and end with a slash (\"%s\")", key, val->s); + return false; + } + + // Check if the path contains only valid characters + return validate_filepath(val, key, err); +} + // Validate file path (empty allowed) bool validate_filepath_empty(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]) { diff --git a/src/config/validator.h b/src/config/validator.h index 12fe3182e..3b5f76dca 100644 --- a/src/config/validator.h +++ b/src/config/validator.h @@ -21,6 +21,7 @@ bool validate_dns_domain(union conf_value *val, const char *key, char err[VALIDA bool validate_cidr(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); bool validate_domain(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); bool validate_filepath(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); +bool validate_filepath_two_slash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); bool validate_filepath_empty(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); bool validate_filepath_dash(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]); bool validate_regex_array(union conf_value *val, const char *key, char err[VALIDATOR_ERRBUF_LEN]);