diff options
| author | 2026-01-06 11:02:36 +0100 | |
|---|---|---|
| committer | 2026-01-06 11:02:36 +0100 | |
| commit | 688c54c87355b5424f33f7b089814460a74af594 (patch) | |
| tree | 03bbe3779173b3d90aede93ea6e41e64869b415b | |
| parent | Version 2.86 RELEASED. (diff) | |
| download | snac2-688c54c87355b5424f33f7b089814460a74af594.tar.gz snac2-688c54c87355b5424f33f7b089814460a74af594.tar.xz snac2-688c54c87355b5424f33f7b089814460a74af594.zip | |
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`.
| -rw-r--r-- | data.c | 13 | ||||
| -rw-r--r-- | doc/snac.8 | 8 | ||||
| -rw-r--r-- | snac.c | 64 | ||||
| -rw-r--r-- | snac.h | 3 |
4 files changed, 86 insertions, 2 deletions
| @@ -89,8 +89,15 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 89 | else { | 89 | else { |
| 90 | if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) | 90 | if (xs_number_get(xs_dict_get(srv_config, "layout")) < disk_layout) |
| 91 | error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); | 91 | error = xs_fmt("ERROR: disk layout changed - execute 'snac upgrade' first"); |
| 92 | else | 92 | else { |
| 93 | ret = 1; | 93 | if (!check_strip_tool()) { |
| 94 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 95 | if (mp == NULL) mp = "mogrify"; | ||
| 96 | error = xs_fmt("ERROR: strip_exif enabled but '%s' not found or not working (set 'mogrify_path' in server.json)", mp); | ||
| 97 | } | ||
| 98 | else | ||
| 99 | ret = 1; | ||
| 100 | } | ||
| 94 | } | 101 | } |
| 95 | } | 102 | } |
| 96 | 103 | ||
| @@ -2710,6 +2717,8 @@ void static_put(snac *snac, const char *id, const char *data, int size) | |||
| 2710 | if (fn && (f = fopen(fn, "wb")) != NULL) { | 2717 | if (fn && (f = fopen(fn, "wb")) != NULL) { |
| 2711 | fwrite(data, size, 1, f); | 2718 | fwrite(data, size, 1, f); |
| 2712 | fclose(f); | 2719 | fclose(f); |
| 2720 | |||
| 2721 | strip_media(fn); | ||
| 2713 | } | 2722 | } |
| 2714 | } | 2723 | } |
| 2715 | 2724 | ||
| @@ -296,6 +296,14 @@ outgoing messages (default: 15). Anyway, whenever any incoming activity from a | |||
| 296 | failed instance is detected, this counter is reset for it. | 296 | failed instance is detected, this counter is reset for it. |
| 297 | .It Ic vkey | 297 | .It Ic vkey |
| 298 | Public vapid key. Used for notification on some client. | 298 | Public vapid key. Used for notification on some client. |
| 299 | .It Ic strip_exif | ||
| 300 | If set to true, EXIF metadata will be stripped from uploaded images (jpg, png, webp, heic, avif, tiff, gif, bmp). This requires the | ||
| 301 | .Nm mogrify | ||
| 302 | tool to be installed. If | ||
| 303 | .Nm snac | ||
| 304 | cannot find or execute the tool at startup, it will refuse to run. | ||
| 305 | .It Ic mogrify_path | ||
| 306 | Overrides the default "mogrify" command name or path. Use this if the tool is not in the system PATH or has a different name. | ||
| 299 | .El | 307 | .El |
| 300 | .Pp | 308 | .Pp |
| 301 | You must restart the server to make effective these changes. | 309 | You must restart the server to make effective these changes. |
| @@ -32,6 +32,7 @@ | |||
| 32 | 32 | ||
| 33 | #include <sys/time.h> | 33 | #include <sys/time.h> |
| 34 | #include <sys/stat.h> | 34 | #include <sys/stat.h> |
| 35 | #include <sys/wait.h> | ||
| 35 | 36 | ||
| 36 | xs_str *srv_basedir = NULL; | 37 | xs_str *srv_basedir = NULL; |
| 37 | xs_dict *srv_config = NULL; | 38 | xs_dict *srv_config = NULL; |
| @@ -170,3 +171,66 @@ int check_password(const char *uid, const char *passwd, const char *hash) | |||
| 170 | 171 | ||
| 171 | return ret; | 172 | return ret; |
| 172 | } | 173 | } |
| 174 | |||
| 175 | |||
| 176 | int strip_media(const char *fn) | ||
| 177 | /* strips EXIF data from a file */ | ||
| 178 | { | ||
| 179 | int ret = 0; | ||
| 180 | const xs_val *v = xs_dict_get(srv_config, "strip_exif"); | ||
| 181 | |||
| 182 | if (xs_type(v) == XSTYPE_TRUE) { | ||
| 183 | xs *l_fn = xs_tolower_i(xs_dup(fn)); | ||
| 184 | |||
| 185 | /* check extensions */ | ||
| 186 | if (xs_endswith(l_fn, ".jpg") || xs_endswith(l_fn, ".jpeg") || | ||
| 187 | xs_endswith(l_fn, ".png") || xs_endswith(l_fn, ".webp") || | ||
| 188 | xs_endswith(l_fn, ".heic") || xs_endswith(l_fn, ".heif") || | ||
| 189 | xs_endswith(l_fn, ".avif") || xs_endswith(l_fn, ".tiff") || | ||
| 190 | xs_endswith(l_fn, ".gif") || xs_endswith(l_fn, ".bmp")) { | ||
| 191 | |||
| 192 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 193 | if (mp == NULL) | ||
| 194 | mp = "mogrify"; | ||
| 195 | |||
| 196 | xs *cmd = xs_fmt("%s -strip \"%s\" 2>/dev/null", mp, fn); | ||
| 197 | |||
| 198 | ret = system(cmd); | ||
| 199 | |||
| 200 | if (ret != 0) { | ||
| 201 | int code = 0; | ||
| 202 | if (WIFEXITED(ret)) | ||
| 203 | code = WEXITSTATUS(ret); | ||
| 204 | |||
| 205 | if (code == 127) | ||
| 206 | srv_log(xs_fmt("strip_media: error stripping %s. '%s' not found (exit 127). Set 'mogrify_path' in server.json.", fn, mp)); | ||
| 207 | else | ||
| 208 | srv_log(xs_fmt("strip_media: error stripping %s %d", fn, ret)); | ||
| 209 | } | ||
| 210 | else | ||
| 211 | srv_debug(1, xs_fmt("strip_media: stripped %s", fn)); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | return ret; | ||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | int check_strip_tool(void) | ||
| 220 | { | ||
| 221 | const xs_val *v = xs_dict_get(srv_config, "strip_exif"); | ||
| 222 | int ret = 1; | ||
| 223 | |||
| 224 | if (xs_type(v) == XSTYPE_TRUE) { | ||
| 225 | const char *mp = xs_dict_get(srv_config, "mogrify_path"); | ||
| 226 | if (mp == NULL) | ||
| 227 | mp = "mogrify"; | ||
| 228 | |||
| 229 | xs *cmd = xs_fmt("%s -version 2>/dev/null >/dev/null", mp); | ||
| 230 | |||
| 231 | if (system(cmd) != 0) | ||
| 232 | ret = 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | return ret; | ||
| 236 | } | ||
| @@ -105,6 +105,9 @@ int validate_uid(const char *uid); | |||
| 105 | xs_str *hash_password(const char *uid, const char *passwd, const char *nonce); | 105 | xs_str *hash_password(const char *uid, const char *passwd, const char *nonce); |
| 106 | int check_password(const char *uid, const char *passwd, const char *hash); | 106 | int check_password(const char *uid, const char *passwd, const char *hash); |
| 107 | 107 | ||
| 108 | int strip_media(const char *fn); | ||
| 109 | int check_strip_tool(void); | ||
| 110 | |||
| 108 | void srv_archive(const char *direction, const char *url, xs_dict *req, | 111 | void srv_archive(const char *direction, const char *url, xs_dict *req, |
| 109 | const char *payload, int p_size, | 112 | const char *payload, int p_size, |
| 110 | int status, xs_dict *headers, | 113 | int status, xs_dict *headers, |