Skip to content

Commit 3e7fe1f

Browse files
Cover newline-tab wrapped invalid baseURL validation paths
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent cc0b1d6 commit 3e7fe1f

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

docs/tasks/streams.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ Examples:
688688
-`\u2007///\u2007` (empty after trimming wrapper whitespace)
689689
-`\u205F///\u205F` (empty after trimming wrapper whitespace)
690690
-`\u3000///\u3000` (empty after trimming wrapper whitespace)
691+
-`\n\thttps://api.trigger.dev/base/?query=1\t\n` (query is still rejected after trimming wrappers)
691692
-`https://api.trigger.dev/\ninternal`
692693
-`https://api.trigger.dev/in valid`
693694
-`https://api.trigger.dev/\tinternal`

packages/ai/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Examples:
195195
-`\u2007///\u2007` (empty after trimming wrapper whitespace)
196196
-`\u205F///\u205F` (empty after trimming wrapper whitespace)
197197
-`\u3000///\u3000` (empty after trimming wrapper whitespace)
198+
-`\n\thttps://api.trigger.dev/base/?query=1\t\n` (query is still rejected after trimming wrappers)
198199
-`https://api.trigger.dev/\ninternal` (internal whitespace characters)
199200
-`https://api.trigger.dev/in valid` (internal space characters)
200201
-`https://api.trigger.dev/\tinternal` (internal tab characters)

packages/ai/src/chatTransport.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,17 @@ describe("TriggerChatTransport", function () {
11051105
}).toThrowError("baseURL must not include query parameters or hash fragments");
11061106
});
11071107

1108+
it("throws when newline-and-tab wrapped baseURL includes query parameters", function () {
1109+
expect(function () {
1110+
new TriggerChatTransport({
1111+
task: "chat-task",
1112+
accessToken: "pk_trigger",
1113+
baseURL: "\n\thttps://example.com/base/?query=1\t\n",
1114+
stream: "chat-stream",
1115+
});
1116+
}).toThrowError("baseURL must not include query parameters or hash fragments");
1117+
});
1118+
11081119
it("throws query/hash validation after trimming wrapper whitespace", function () {
11091120
expect(function () {
11101121
new TriggerChatTransport({
@@ -1138,6 +1149,17 @@ describe("TriggerChatTransport", function () {
11381149
}).toThrowError("baseURL must not include query parameters or hash fragments");
11391150
});
11401151

1152+
it("throws when newline-and-tab wrapped baseURL includes hash fragments", function () {
1153+
expect(function () {
1154+
new TriggerChatTransport({
1155+
task: "chat-task",
1156+
accessToken: "pk_trigger",
1157+
baseURL: "\n\thttps://example.com/base/#fragment\t\n",
1158+
stream: "chat-stream",
1159+
});
1160+
}).toThrowError("baseURL must not include query parameters or hash fragments");
1161+
});
1162+
11411163
it("throws when baseURL includes username or password credentials", function () {
11421164
expect(function () {
11431165
new TriggerChatTransport({
@@ -1226,6 +1248,17 @@ describe("TriggerChatTransport", function () {
12261248
}).toThrowError("baseURL must not include username or password credentials");
12271249
});
12281250

1251+
it("throws when newline-and-tab wrapped baseURL includes username or password credentials", function () {
1252+
expect(function () {
1253+
new TriggerChatTransport({
1254+
task: "chat-task",
1255+
accessToken: "pk_trigger",
1256+
baseURL: "\n\thttps://user:pass@example.com/base/\t\n",
1257+
stream: "chat-stream",
1258+
});
1259+
}).toThrowError("baseURL must not include username or password credentials");
1260+
});
1261+
12291262
it("accepts https baseURL values without throwing", function () {
12301263
expect(function () {
12311264
new TriggerChatTransport({
@@ -4064,6 +4097,17 @@ describe("TriggerChatTransport", function () {
40644097
}).toThrowError("baseURL must not include query parameters or hash fragments");
40654098
});
40664099

4100+
it("throws from factory when newline-and-tab wrapped baseURL includes query parameters", function () {
4101+
expect(function () {
4102+
createTriggerChatTransport({
4103+
task: "chat-task",
4104+
accessToken: "pk_trigger",
4105+
baseURL: "\n\thttps://example.com/base/?query=1\t\n",
4106+
stream: "chat-stream",
4107+
});
4108+
}).toThrowError("baseURL must not include query parameters or hash fragments");
4109+
});
4110+
40674111
it("throws query/hash validation after trimming wrapper whitespace in factory", function () {
40684112
expect(function () {
40694113
createTriggerChatTransport({
@@ -4097,6 +4141,17 @@ describe("TriggerChatTransport", function () {
40974141
}).toThrowError("baseURL must not include query parameters or hash fragments");
40984142
});
40994143

4144+
it("throws from factory when newline-and-tab wrapped baseURL includes hash fragments", function () {
4145+
expect(function () {
4146+
createTriggerChatTransport({
4147+
task: "chat-task",
4148+
accessToken: "pk_trigger",
4149+
baseURL: "\n\thttps://example.com/base/#fragment\t\n",
4150+
stream: "chat-stream",
4151+
});
4152+
}).toThrowError("baseURL must not include query parameters or hash fragments");
4153+
});
4154+
41004155
it("throws from factory when baseURL includes username or password credentials", function () {
41014156
expect(function () {
41024157
createTriggerChatTransport({
@@ -4185,6 +4240,17 @@ describe("TriggerChatTransport", function () {
41854240
}).toThrowError("baseURL must not include username or password credentials");
41864241
});
41874242

4243+
it("throws from factory when newline-and-tab wrapped baseURL includes username or password credentials", function () {
4244+
expect(function () {
4245+
createTriggerChatTransport({
4246+
task: "chat-task",
4247+
accessToken: "pk_trigger",
4248+
baseURL: "\n\thttps://user:pass@example.com/base/\t\n",
4249+
stream: "chat-stream",
4250+
});
4251+
}).toThrowError("baseURL must not include username or password credentials");
4252+
});
4253+
41884254
it("accepts https baseURL values from factory without throwing", function () {
41894255
expect(function () {
41904256
createTriggerChatTransport({

0 commit comments

Comments
 (0)