fix(gitstat): compare allowlist prefixes against the canonical root
macOS resolves /tmp and /var through symlinks, so realpath() of a fixture path returns /private/tmp/... while the configured root still reads /tmp/.... The raw prefix test then refused every detail and fetch request with 403 on the Mac (the Linux suite never noticed). Keep both forms: root is what the operator wrote, canon is what the prefix check compares against.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 09:43:47
Commit843327b0
Parents8a37d0bd
Changed files
src/plugin_gitstat.c+12−3■■■■■
1 file+12−3
Diff
src/plugin_gitstat.c+12−3■■■■■
index d0359e3..c3eacb2 100644
--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c
@@ -584,7 +584,8 @@ static repo_t g_repos[MAX_REPOS];
584584 static int g_repo_count;
585585
586586 typedef struct {
587- char root[768];
587+ char root[768]; /* as configured, for display */
588+ char canon[768]; /* realpath() form, for the prefix check */
588589 int exists;
589590 int count;
590591 int truncated;
@@ -717,6 +718,9 @@ static void walk_dir(const char *dir, const char *root, int depth,
717718 }
718719 }
719720
721+static void canon_path(const char *in, char *out, size_t sz);
722+static int path_exists(const char *p);
723+
720724 static void root_add(const char *root, const char *sep_list_used)
721725 {
722726 (void)sep_list_used;
@@ -728,6 +732,7 @@ static void root_add(const char *root, const char *sep_list_used)
728732 if (strcmp(g_roots[i].root, root) == 0) return;
729733 }
730734 str_copy(g_roots[g_root_count].root, sizeof(g_roots[g_root_count].root), root);
735+ canon_path(root, g_roots[g_root_count].canon, sizeof(g_roots[g_root_count].canon));
731736 g_roots[g_root_count].exists = 0;
732737 g_roots[g_root_count].count = 0;
733738 g_roots[g_root_count].truncated = 0;
@@ -1057,9 +1062,13 @@ static int under_root(const char *path)
10571062 {
10581063 int i;
10591064 for (i = 0; i < g_root_count; i++) {
1060- size_t n = strlen(g_roots[i].root);
1065+ /* Compare against the canonical root, not the configured string: on
1066+ * macOS /tmp and /var are symlinks, so realpath("/tmp/x") is
1067+ * "/private/tmp/x" and a raw prefix test would refuse every path. */
1068+ const char *r = g_roots[i].canon[0] ? g_roots[i].canon : g_roots[i].root;
1069+ size_t n = strlen(r);
10611070 if (n == 0) continue;
1062- if (strncmp(path, g_roots[i].root, n) != 0) continue;
1071+ if (strncmp(path, r, n) != 0) continue;
10631072 if (path[n] == '\0' || path[n] == '/' || path[n] == '\\') return 1;
10641073 }
10651074 return 0;
10661075
src/plugin_gitstat.c+12−3■■■■■
index d0359e3..c3eacb2 100644index d0359e3..c3eacb2 100644
--- a/src/plugin_gitstat.c--- a/src/plugin_gitstat.c
+++ b/src/plugin_gitstat.c+++ b/src/plugin_gitstat.c
@@ -584,7 +584,8 @@ static repo_t g_repos[MAX_REPOS];@@ -584,7 +584,8 @@ static repo_t g_repos[MAX_REPOS];
584 static int g_repo_count;584 static int g_repo_count;
585 585
586 typedef struct {586 typedef struct {
587- char root[768];587+ char root[768]; /* as configured, for display */
588+ char canon[768]; /* realpath() form, for the prefix check */
588 int exists;589 int exists;
589 int count;590 int count;
590 int truncated;591 int truncated;
@@ -717,6 +718,9 @@ static void walk_dir(const char *dir, const char *root, int depth,@@ -717,6 +718,9 @@ static void walk_dir(const char *dir, const char *root, int depth,
717 }718 }
718 }719 }
719 720
721+static void canon_path(const char *in, char *out, size_t sz);
722+static int path_exists(const char *p);
723+
720 static void root_add(const char *root, const char *sep_list_used)724 static void root_add(const char *root, const char *sep_list_used)
721 {725 {
722 (void)sep_list_used;726 (void)sep_list_used;
@@ -728,6 +732,7 @@ static void root_add(const char *root, const char *sep_list_used)@@ -728,6 +732,7 @@ static void root_add(const char *root, const char *sep_list_used)
728 if (strcmp(g_roots[i].root, root) == 0) return;732 if (strcmp(g_roots[i].root, root) == 0) return;
729 }733 }
730 str_copy(g_roots[g_root_count].root, sizeof(g_roots[g_root_count].root), root);734 str_copy(g_roots[g_root_count].root, sizeof(g_roots[g_root_count].root), root);
735+ canon_path(root, g_roots[g_root_count].canon, sizeof(g_roots[g_root_count].canon));
731 g_roots[g_root_count].exists = 0;736 g_roots[g_root_count].exists = 0;
732 g_roots[g_root_count].count = 0;737 g_roots[g_root_count].count = 0;
733 g_roots[g_root_count].truncated = 0;738 g_roots[g_root_count].truncated = 0;
@@ -1057,9 +1062,13 @@ static int under_root(const char *path)@@ -1057,9 +1062,13 @@ static int under_root(const char *path)
1057 {1062 {
1058 int i;1063 int i;
1059 for (i = 0; i < g_root_count; i++) {1064 for (i = 0; i < g_root_count; i++) {
1060- size_t n = strlen(g_roots[i].root);1065+ /* Compare against the canonical root, not the configured string: on
1066+ * macOS /tmp and /var are symlinks, so realpath("/tmp/x") is
1067+ * "/private/tmp/x" and a raw prefix test would refuse every path. */
1068+ const char *r = g_roots[i].canon[0] ? g_roots[i].canon : g_roots[i].root;
1069+ size_t n = strlen(r);
1061 if (n == 0) continue;1070 if (n == 0) continue;
1062- if (strncmp(path, g_roots[i].root, n) != 0) continue;1071+ if (strncmp(path, r, n) != 0) continue;
1063 if (path[n] == '\0' || path[n] == '/' || path[n] == '\\') return 1;1072 if (path[n] == '\0' || path[n] == '/' || path[n] == '\\') return 1;
1064 }1073 }
1065 return 0;1074 return 0;
10661075