@@ -261,6 +261,96 @@ TEST(ws_manifest_approval_refuses_overbroad_requests) {
261261 PASS ();
262262}
263263
264+ /* #1718: the sensitive-root escape hatch broke on Windows separator spelling.
265+ * The grant is recorded from cbm_canonical_path — backslashes — while the
266+ * indexer hands the candidate already normalized to '/'. A byte-exact
267+ * comparison made the grant never match the candidate, so an approved
268+ * "Program Files" root stayed refused. '/' and '\' are equivalent everywhere
269+ * else in this module (ws_is_sep); the boundary comparison must treat them
270+ * equally. The classify_root home rule uses the same ws_paths_equal, so a
271+ * mixed-separator home spelling is the string-level regression check; the
272+ * FS-backed grant round-trip lives in the _WIN32 half, where the real
273+ * canonicalization exercises it. */
274+ TEST (ws_approve_sensitive_matches_across_separator_styles ) {
275+ /* canonical spelled with '\' vs home spelled with '/' — must classify as
276+ * the same directory. Pre-fix: strncmp mismatch at the separator byte, so
277+ * the home rule never matched and an ordinary path under "C:\Users" fell
278+ * through to CBM_WS_ALLOW. */
279+ ASSERT_EQ (cbm_workspace_classify_root ("C:\\Users\\dev" , "C:/Users/dev" , CACHE ),
280+ CBM_WS_DENY_SENSITIVE );
281+ ASSERT_EQ (cbm_workspace_classify_root ("C:/Users/dev" , "C:\\Users\\dev" , CACHE ),
282+ CBM_WS_DENY_SENSITIVE );
283+ /* A sibling that differs after the same separator boundary is still a
284+ * different directory: "/a/bc" must never look like "/a/b". */
285+ ASSERT_EQ (cbm_workspace_classify_root ("C:\\Users\\devx" , "C:/Users/dev" , CACHE ), CBM_WS_ALLOW );
286+ #ifdef _WIN32
287+ /* Full grant round-trip on real filesystem paths: the grant stored with
288+ * '\' must lift the exact candidate the indexer passes with '/'. The
289+ * sensitive class is exercised by a credential-named directory (".ssh"),
290+ * which is DENY_SENSITIVE at any depth — equivalent to "Program Files"
291+ * for the refusal path under test. */
292+ char * cache = th_mktempdir ("cbm_ws_sw" );
293+ ASSERT (cache != NULL );
294+ char dir [1024 ];
295+ snprintf (dir , sizeof (dir ), "%s/.ssh/cfg" , cache );
296+ ASSERT_TRUE (cbm_mkdir_p (dir , 0700 ));
297+ char path [1024 ];
298+ snprintf (path , sizeof (path ), "%s/allowed_roots" , cache );
299+
300+ char grant [2048 ];
301+ snprintf (grant , sizeof (grant ), "!%s\\.ssh\\cfg\n" , cache );
302+ FILE * f = fopen (path , "w" );
303+ ASSERT_NOT_NULL (f );
304+ (void )fprintf (f , "%s" , grant );
305+ (void )fclose (f );
306+
307+ char candidate [2048 ];
308+ snprintf (candidate , sizeof (candidate ), "%s/.ssh/cfg" , cache );
309+ /* Convert to '/' spelling, exactly as cbm_normalize_path_sep does for the
310+ * indexer's candidate. */
311+ char * p ;
312+ for (p = candidate ; * p ; p ++ ) {
313+ if (* p == '\\' ) {
314+ * p = '/' ;
315+ }
316+ }
317+ char err [1024 ];
318+ err [0 ] = '\0' ;
319+ ASSERT_TRUE (cbm_workspace_root_allowed (candidate , NULL , cache , NULL , err , sizeof (err )));
320+
321+ /* An unapproved sibling under the same sensitive tree stays refused. It
322+ * lies outside every granted root, so the refusal is the boundary wording
323+ * (kept verbatim by contract), not the sensitive hint. */
324+ char sibling [2048 ];
325+ snprintf (sibling , sizeof (sibling ), "%s/.ssh/keys" , cache );
326+ for (p = sibling ; * p ; p ++ ) {
327+ if (* p == '\\' ) {
328+ * p = '/' ;
329+ }
330+ }
331+ err [0 ] = '\0' ;
332+ ASSERT_FALSE (cbm_workspace_root_allowed (sibling , NULL , cache , NULL , err , sizeof (err )));
333+ ASSERT_TRUE (strstr (err , "outside the allowed root" ) != NULL );
334+
335+ /* A strict descendant INSIDE the approved sensitive grant is contained
336+ * (boundary passes) but not the exact grant, so the sensitive refusal
337+ * applies and the hint names the flag. */
338+ char descendant [2048 ];
339+ snprintf (descendant , sizeof (descendant ), "%s/.ssh/cfg/sub" , cache );
340+ for (p = descendant ; * p ; p ++ ) {
341+ if (* p == '\\' ) {
342+ * p = '/' ;
343+ }
344+ }
345+ err [0 ] = '\0' ;
346+ ASSERT_FALSE (cbm_workspace_root_allowed (descendant , NULL , cache , NULL , err , sizeof (err )));
347+ ASSERT_TRUE (strstr (err , "--approve-sensitive" ) != NULL );
348+
349+ th_cleanup (cache );
350+ #endif
351+ PASS ();
352+ }
353+
264354SUITE (workspace ) {
265355 RUN_TEST (ws_manifest_absent_is_not_an_error );
266356 RUN_TEST (ws_manifest_parses_entries_and_skips_comments );
@@ -278,4 +368,5 @@ SUITE(workspace) {
278368 RUN_TEST (ws_posix_matching_is_case_sensitive );
279369 RUN_TEST (ws_null_context_disables_dependent_checks );
280370 RUN_TEST (ws_every_verdict_has_a_reason );
371+ RUN_TEST (ws_approve_sensitive_matches_across_separator_styles );
281372}
0 commit comments