From 688c54c87355b5424f33f7b089814460a74af594 Mon Sep 17 00:00:00 2001 From: Stefano Marinelli Date: Tue, 6 Jan 2026 11:02:36 +0100 Subject: Implement configurable EXIF stripping for uploaded media - Add `strip_exif` configuration option to enable metadata removal. - Add `mogrify_path` configuration to specify external tool location. - Implement strip_media using `mogrify -strip`. - Support multiple image formats: jpg, png, webp, heic, heif, avif, tiff, gif, bmp. - Add strict startup check: fail to start if `strip_exif` is enabled but `mogrify` is missing/broken. - Update documentation in `doc/snac.8`. --- snac.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'snac.c') diff --git a/snac.c b/snac.c index 965edbb..f4528cd 100644 --- a/snac.c +++ b/snac.c @@ -32,6 +32,7 @@ #include #include +#include xs_str *srv_basedir = NULL; xs_dict *srv_config = NULL; @@ -170,3 +171,66 @@ int check_password(const char *uid, const char *passwd, const char *hash) return ret; } + + +int strip_media(const char *fn) +/* strips EXIF data from a file */ +{ + int ret = 0; + const xs_val *v = xs_dict_get(srv_config, "strip_exif"); + + if (xs_type(v) == XSTYPE_TRUE) { + xs *l_fn = xs_tolower_i(xs_dup(fn)); + + /* check extensions */ + if (xs_endswith(l_fn, ".jpg") || xs_endswith(l_fn, ".jpeg") || + xs_endswith(l_fn, ".png") || xs_endswith(l_fn, ".webp") || + xs_endswith(l_fn, ".heic") || xs_endswith(l_fn, ".heif") || + xs_endswith(l_fn, ".avif") || xs_endswith(l_fn, ".tiff") || + xs_endswith(l_fn, ".gif") || xs_endswith(l_fn, ".bmp")) { + + const char *mp = xs_dict_get(srv_config, "mogrify_path"); + if (mp == NULL) + mp = "mogrify"; + + xs *cmd = xs_fmt("%s -strip \"%s\" 2>/dev/null", mp, fn); + + ret = system(cmd); + + if (ret != 0) { + int code = 0; + if (WIFEXITED(ret)) + code = WEXITSTATUS(ret); + + if (code == 127) + srv_log(xs_fmt("strip_media: error stripping %s. '%s' not found (exit 127). Set 'mogrify_path' in server.json.", fn, mp)); + else + srv_log(xs_fmt("strip_media: error stripping %s %d", fn, ret)); + } + else + srv_debug(1, xs_fmt("strip_media: stripped %s", fn)); + } + } + + return ret; +} + + +int check_strip_tool(void) +{ + const xs_val *v = xs_dict_get(srv_config, "strip_exif"); + int ret = 1; + + if (xs_type(v) == XSTYPE_TRUE) { + const char *mp = xs_dict_get(srv_config, "mogrify_path"); + if (mp == NULL) + mp = "mogrify"; + + xs *cmd = xs_fmt("%s -version 2>/dev/null >/dev/null", mp); + + if (system(cmd) != 0) + ret = 0; + } + + return ret; +} -- cgit v1.2.3