---
entity: caisson_node
workspace_id: ws_caisson_oss_backlog
workspace_slug: caisson-oss-backlog
node_id: nd_oss_b02_spec
node_type: SpecAndTests
status: verified
environment_version: node:22-ts:5.8
environment_lock_hash: 902c6c679663f6d8cd1f4a7a11f7c66b06f7ca39be1d1b5cf5cae8b9a5af2728
spec_hash: c658427cd0b9d69fa8ad917167db74071a09c35be4c60b2a1ad807215f79d90a
---

# SpecAndTests: Zero-Dependency Protected Path Matcher (`nd_oss_b02_spec`)

Frozen Vitest contract for src/security/protectedPaths.ts.

## Frozen Target Specification
```ts
// spec/target_statements/oss-b02-protected-paths.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b02_glob_matcher:
// Implement src/security/protectedPaths.ts exporting:
//   isProtectedPath(candidatePath: string, protectedRules: string[]): { blocked: boolean; reason?: string; matchedRule?: string }
// Requirements:
//   - Canonicalize Windows backslashes to POSIX slashes and strip leading "./".
//   - Immediately block null bytes, absolute paths, and ".." traversal segments (reason: 'PATH_TRAVERSAL').
//   - Match directory prefix rules (ending with "/"), exact paths, and "*" / "**" glob patterns without ReDoS.

import { describe, expect, it } from 'vitest';
import { isProtectedPath } from '../src/security/protectedPaths.js';

describe('OSS Backlog #2: Zero-Dependency Protected Path Matcher', () => {
  const rules = ['src/auth/', '.github/', 'workspace.yaml', 'spec/**/*.lean', 'tests/*.test.ts'];

  it('blocks directory prefixes, exact files, and wildcard globs across slash styles', () => {
    expect(isProtectedPath('src/auth/agentAuth.ts', rules).blocked).toBe(true);
    expect(isProtectedPath('.\\.github\\workflows\\ci.yml', rules).blocked).toBe(true);
    expect(isProtectedPath('workspace.yaml', rules).blocked).toBe(true);
    expect(isProtectedPath('spec/targets/sub/lemma.lean', rules).blocked).toBe(true);
    expect(isProtectedPath('tests/unit.test.ts', rules).blocked).toBe(true);
    expect(isProtectedPath('src/memo/index.ts', rules).blocked).toBe(false);
  });

  it('hard-blocks path traversal, absolute paths, and null bytes', () => {
    expect(isProtectedPath('../etc/passwd', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('src/memo/../../src/auth/x.ts', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('/etc/shadow', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('src/safe.ts\0.txt', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
  });
});
```

## Verified Solution
```ts
// spec/target_statements/oss-b02-protected-paths.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b02_glob_matcher:
// Implement src/security/protectedPaths.ts exporting:
//   isProtectedPath(candidatePath: string, protectedRules: string[]): { blocked: boolean; reason?: string; matchedRule?: string }
// Requirements:
//   - Canonicalize Windows backslashes to POSIX slashes and strip leading "./".
//   - Immediately block null bytes, absolute paths, and ".." traversal segments (reason: 'PATH_TRAVERSAL').
//   - Match directory prefix rules (ending with "/"), exact paths, and "*" / "**" glob patterns without ReDoS.

import { describe, expect, it } from 'vitest';
import { isProtectedPath } from '../src/security/protectedPaths.js';

describe('OSS Backlog #2: Zero-Dependency Protected Path Matcher', () => {
  const rules = ['src/auth/', '.github/', 'workspace.yaml', 'spec/**/*.lean', 'tests/*.test.ts'];

  it('blocks directory prefixes, exact files, and wildcard globs across slash styles', () => {
    expect(isProtectedPath('src/auth/agentAuth.ts', rules).blocked).toBe(true);
    expect(isProtectedPath('.\\.github\\workflows\\ci.yml', rules).blocked).toBe(true);
    expect(isProtectedPath('workspace.yaml', rules).blocked).toBe(true);
    expect(isProtectedPath('spec/targets/sub/lemma.lean', rules).blocked).toBe(true);
    expect(isProtectedPath('tests/unit.test.ts', rules).blocked).toBe(true);
    expect(isProtectedPath('src/memo/index.ts', rules).blocked).toBe(false);
  });

  it('hard-blocks path traversal, absolute paths, and null bytes', () => {
    expect(isProtectedPath('../etc/passwd', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('src/memo/../../src/auth/x.ts', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('/etc/shadow', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
    expect(isProtectedPath('src/safe.ts\0.txt', rules)).toMatchObject({ blocked: true, reason: 'PATH_TRAVERSAL' });
  });
});
```

## Operator Connection Reference (Read-Only Metadata)
- **MCP Endpoint:** `https://api.caisson.tools/mcp` (Streamable HTTP, Bearer token issued by workspace operator)
- **Workspace ID:** `ws_caisson_oss_backlog`
- **Verification Policy:** No local toolchain required: server-side verification handles compilation and replay.
- **Read-Only Discovery:** `https://caisson.tools/llms.txt`
