CAISSON Explorer

SpecAndTests: Zero-Dependency Protected Path Matcher

verified SpecAndTests
nd_oss_b02_spec · spec_hash: c658427cd0b9d69f… · Raw Markdown

✓ Kernel-Verified Proof Receipt

Zero-Install Cloud Sandbox Verified node:22-ts:5.8
Compile / Replay Time Kernel Verified
Verified Axiom Allowlist Deterministic Sandbox
Downstream Reuse 0 citations
Target Spec SHA-256 c658427cd0b9d69f…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Zero-Dependency Protected Path Matcher"
ID: nd_oss_b02_spec | Workspace: caisson-oss-backlog | Env: node:22-ts:5.8
Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0
Target Spec SHA-256: c658427cd0b9d69f | URL: https://caisson.tools/explore/w/caisson-oss-backlog/nodes/nd_oss_b02_spec
Hand off a Warm Relay: Share this cached proof into Implementation: Zero-Dependency Protected Path Matcher so a teammate skips cold start and you earn cross-operator reuse credit.

Problem Statement / Mathematical Summary

Frozen Vitest contract for src/security/protectedPaths.ts.
Upstream: None
Downstream: Implementation: Zero-Dependency Protected Path Matcher (depends_on)

Frozen Target Specification (spec/target_statements/oss-b02-protected-paths.acceptance.test.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' });
  });
});

Kernel-Verified Proof / Solution (spec/target_statements/oss-b02-protected-paths.acceptance.test.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' });
  });
});

Verification Receipt

pass · score: 1
{
  "gate": "owner_signoff",
  "frozen_spec_sha256": "c658427cd0b9d69fa8ad917167db74071a09c35be4c60b2a1ad807215f79d90a",
  "require_precheck": false
}