Skip to main content
Menu
Advisories

Local $ref path-confinement bypassable when the spec path is relative (incomplete fix of CVE-2026-63415 / GHSA-c3cj-3p6p-j822)

GHSA-WVJC-3XV7-JR55Published Updated GitHub

Description

The fix for CVE-2026-63415 added Reference::validateLocalPath() to keep a local $ref inside the referencing document's directory. The check is bypassable when the spec path (the generation origin) is relative, which lets an attacker-influenced OpenAPI or JSON Schema document read files outside the intended spec directory at code-generation time. The leaked file content is fetched on the build host and inlined into the generated schema graph. Deep traversal and absolute-path refs are still blocked, so this is a partial regression rather than a full return of the original issue. Present at HEAD (next) and in the latest release v8.1.2.

Details

Sink: Reference::doResolve() calls fetchAndNormalizeContents(), which does @file_get_contents($fragment) (src/Component/JsonSchemaRuntime/Reference.php:140).

Guard: validateReference() routes local refs to validateLocalPath($fragment) (Reference.php:230-289). For a relative fragment it rebuilds the path it validates by prepending the realpath of the origin's directory:

// Reference.php ~269 if (!str_starts_with($path, '/') && !preg_match('#^[a-zA-Z]:/#', $path)) { $path = $basePath . '/' . $path; // basePath = realpath(dirname(origin)) } // ... then: $normalized startsWith one of the allowed bases -> allowed

The mismatch: the containment check measures the fragment from $basePath (the spec directory), but file_get_contents($fragment) at line 140 resolves the same relative fragment against the process current working directory. joinPath() (Reference.php:379-412) collapses the .. of a $ref relative to the origin's directory, so for a relative origin the fragment comes out relative with the escaping .. already consumed. When the CWD is an ancestor of the spec directory (the common "spec lives in a subdirectory, run jane from the project root" layout), the validator and the fetch resolve the fragment against different base directories and a ../-collapsing ref escapes the spec directory.

The origin stays relative in the normal pipeline: SchemaLoader builds new Schema($openapi-file, ...) and the Schema constructor only normalizes separators (no realpath, src/Component/JsonSchema/Registry/Schema.php:47); GenerateCommand/ConfigLoader do not chdir or absolutize. Normalizers then build new Reference($ref, $context['document-origin']) with that relative origin (for example OpenApi3/JsonSchema/Normalizer/ResponseNormalizer.php:47).

Proof of concept

Executed, PHP 8.5, HEAD source. Project layout: proj/spec/openapi.json is the spec, proj/secret.txt sits in the project root (outside spec/). Run with CWD = proj.

chdir($proj); // CWD = project root ReferenceResolver::default()->resetConfiguration(); // defaults: external off, no extra roots $ref = new Reference('../secret.txt', 'spec/openapi.json'); // relative origin var_dump($ref->resolve());

Observed:

  • Relative origin spec/openapi.json, ref ../secret.txt: resolve() returned the JSON contents of proj/secret.txt (outside the spec directory). No exception. Confinement bypassed.
  • Second case, origin openapi/api.json, ref ../dbconfig.json: returned the contents of proj/dbconfig.json (a project-root secret).
  • Control, same ref with an absolute origin (/abs/proj/spec/openapi.json): correctly rejected with "resolves outside the allowed directories".

A ref that still has a leading .. after collapse (for example ../../../../etc/passwd) is correctly rejected, so the reachable scope is the current working directory subtree (typically the whole project: .env, config, source, other specs), not the entire filesystem.

Impact

At build or CI time, generating from an attacker-influenced spec reads files from the project working directory that are outside the intended spec directory and inlines them into the generated output. Reading a spec from an untrusted source is the exact threat model of CVE-2026-63415. The confinement that fix introduced does not hold for the common relative-spec-path configuration. CWE-22 (incomplete fix; relates to CWE-98).

Scope note (stated plainly): this is reachable when openapi-file is configured as a relative path and jane runs from a directory above the spec directory. It is not reachable in the configurations the Jane examples use (absolute openapi-file via __DIR__). Reported as an incomplete fix of GHSA-c3cj-3p6p-j822, not a new vulnerability class.

Suggested direction: validate the exact target that will be read rather than a reconstructed one (resolve the fetch target and the allowed base to canonical paths once and compare those), or absolutize the origin before any Reference is constructed so the fragment and the fetch share a base. A regression test with a relative origin, a subdirectory spec, and a ../file ref would cover it.

Affected versions

References

GitHub · janephp/janephp