Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/internal/utils/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import { OpenAIError } from '../../core/error';

// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
//
// Restricted to http(s) to avoid bypassing baseURL through dangerous schemes
// (file:, gopher:, ftp:, data:, javascript:) when an absolute-URL path is
// passed to client.get / client.post. The SDK's typed resource methods use
// hardcoded relative paths, so this narrows the regex to the only schemes
// the SDK is meant to construct outbound requests against.
const startsWithSchemeRegexp = /^https?:/i;

export const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
Expand Down