Skip to content

Commit 39492e6

Browse files
Reject credential-bearing baseURL values
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 7f4cca5 commit 39492e6

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

docs/tasks/streams.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ If `onError` is omitted, reconnect still returns `null` and continues without ca
656656
`baseURL` supports optional path prefixes and trailing slashes; both trigger and stream URLs
657657
are normalized consistently, surrounding whitespace is trimmed before normalization, and
658658
the resulting value must not be empty. The value must also be a valid absolute URL using
659-
the `http` or `https` protocol, without query parameters or hash fragments.
659+
the `http` or `https` protocol, without query parameters, hash fragments, or embedded
660+
username/password credentials.
660661

661662
For richer TypeScript ergonomics in app code, `@trigger.dev/ai` also exports:
662663

packages/ai/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
- Added explicit validation that `baseURL` is a valid absolute URL.
2626
- Added explicit validation that `baseURL` uses `http` or `https`.
2727
- Added explicit validation that `baseURL` excludes query parameters and hash fragments.
28+
- Added explicit validation that `baseURL` excludes username/password credentials.

packages/ai/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ both cleanup steps (`set` inactive state and `delete`) even if one of them fails
164164
- `baseURL` must be a valid absolute URL.
165165
- `baseURL` must use the `http` or `https` protocol.
166166
- `baseURL` must not include query parameters or hash fragments.
167+
- `baseURL` must not include username/password URL credentials.
167168

168169
## `ai.tool(...)` example
169170

packages/ai/src/chatTransport.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ describe("TriggerChatTransport", function () {
675675
}).toThrowError("baseURL must not include query parameters or hash fragments");
676676
});
677677

678+
it("throws when baseURL includes username or password credentials", function () {
679+
expect(function () {
680+
new TriggerChatTransport({
681+
task: "chat-task",
682+
accessToken: "pk_trigger",
683+
baseURL: "https://user:pass@example.com/base",
684+
stream: "chat-stream",
685+
});
686+
}).toThrowError("baseURL must not include username or password credentials");
687+
});
688+
678689
it("accepts https baseURL values without throwing", function () {
679690
expect(function () {
680691
new TriggerChatTransport({
@@ -2925,6 +2936,17 @@ describe("TriggerChatTransport", function () {
29252936
}).toThrowError("baseURL must not include query parameters or hash fragments");
29262937
});
29272938

2939+
it("throws from factory when baseURL includes username or password credentials", function () {
2940+
expect(function () {
2941+
createTriggerChatTransport({
2942+
task: "chat-task",
2943+
accessToken: "pk_trigger",
2944+
baseURL: "https://user:pass@example.com/base",
2945+
stream: "chat-stream",
2946+
});
2947+
}).toThrowError("baseURL must not include username or password credentials");
2948+
});
2949+
29282950
it("accepts https baseURL values from factory without throwing", function () {
29292951
expect(function () {
29302952
createTriggerChatTransport({

packages/ai/src/chatTransport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ function normalizeBaseUrl(baseURL: string) {
484484
throw new Error("baseURL must not include query parameters or hash fragments");
485485
}
486486

487+
if (parsedBaseUrl.username.length > 0 || parsedBaseUrl.password.length > 0) {
488+
throw new Error("baseURL must not include username or password credentials");
489+
}
490+
487491
return normalizedBaseUrl;
488492
}
489493

0 commit comments

Comments
 (0)