Commit f951d8b
committed
fix(engine): allow symlinks that resolve inside the project root
The ancestor-symlink check from #499 rejected any symlinked path component
below the project root, regardless of where it pointed. That over-rejects: a
link resolving back inside the project escapes nothing, and symlinked
directories inside a repository are an ordinary layout. Workspace monorepos
symlink node_modules/<pkg> to packages/<pkg> (pnpm, npm, yarn and bun all do
this), and projects symlink shared source directories — so archgate refused
to read files it is meant to govern, failing the rule with "access denied".
The gate is now where a symlink POINTS rather than that one exists: each
component below the root is resolved and rejected only when its target lands
outside the root. The escape #499 closed stays closed — an outside-pointing
link is still rejected at any component, including after an earlier hop that
legitimately stayed inside.
Comparison is realpath-against-realpath, never realpath-against-lexical:
realpath case-canonicalizes on Windows and macOS, so mixing the two would
reject case-mismatched-but-legitimate paths. Both sides are resolved so the
same canonicalization applies to each, and the root's own realpath is
memoized alongside the per-component memo.
The component memo is keyed by (root, component) rather than component
alone: the same component can sit under two roots with different verdicts,
since a link leaving root A may land inside an enclosing root B.
Note this also relaxes the pre-existing LEAF symlink check, which likewise
rejected in-project links. Leaving the leaf strict while allowing ancestors
would be arbitrary — a file reachable as packages/shared/index.ts should not
become unreadable because it is also linked as index.ts.
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>1 parent 9a114b3 commit f951d8b
2 files changed
Lines changed: 120 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
39 | 60 | | |
40 | 61 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
46 | 67 | | |
47 | | - | |
48 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
49 | 71 | | |
50 | | - | |
| 72 | + | |
51 | 73 | | |
52 | 74 | | |
53 | 75 | | |
| |||
57 | 79 | | |
58 | 80 | | |
59 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
60 | 88 | | |
61 | | - | |
| 89 | + | |
62 | 90 | | |
63 | | - | |
| 91 | + | |
64 | 92 | | |
65 | 93 | | |
66 | 94 | | |
| |||
70 | 98 | | |
71 | 99 | | |
72 | 100 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
78 | 112 | | |
79 | | - | |
| 113 | + | |
80 | 114 | | |
81 | 115 | | |
82 | 116 | | |
83 | 117 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
87 | 123 | | |
88 | 124 | | |
89 | 125 | | |
| |||
92 | 128 | | |
93 | 129 | | |
94 | 130 | | |
95 | | - | |
| 131 | + | |
96 | 132 | | |
97 | 133 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
102 | 124 | | |
103 | 125 | | |
104 | 126 | | |
| |||
109 | 131 | | |
110 | 132 | | |
111 | 133 | | |
112 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
113 | 168 | | |
114 | 169 | | |
115 | 170 | | |
| |||
0 commit comments