Skip to content
Merged
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
10 changes: 9 additions & 1 deletion apps/gateway/src/videos/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,15 @@ async function fetchUpstreamJson(

if (text.length > 0) {
try {
body = JSON.parse(text) as Record<string, unknown>;
const parsed: unknown = JSON.parse(text);
body =
typeof parsed === "object" && parsed !== null
? (parsed as Record<string, unknown>)
: {
Comment on lines +2719 to +2721

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve JSON string upload URLs

When AtlasCloud's media upload responds with a valid JSON string containing a URL, such as "https://...", this branch now wraps the parsed string in { error: { message: text } } instead of returning the string. uploadAtlasCloudMedia immediately passes this value to extractAtlasCloudUploadedMediaUrl, which has an explicit top-level string URL case, so those uploads regress from succeeding to AtlasCloud media upload did not return a usable URL; the null crash guard should not discard string primitives that existing extraction logic can handle.

Useful? React with 👍 / 👎.

Comment on lines +2719 to +2721

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Exclude arrays in the parsed-body guard to preserve response contract.

On Line 2719, the object check still accepts arrays (typeof [] === "object"), so array JSON payloads bypass the fallback and are returned as Record<string, unknown>. That contradicts the intended behavior for non-object payloads and can leak invalid body shapes downstream.

Suggested fix
-			body =
-				typeof parsed === "object" && parsed !== null
+			body =
+				typeof parsed === "object" &&
+				parsed !== null &&
+				!Array.isArray(parsed)
 					? (parsed as Record<string, unknown>)
 					: {
 							error: {
 								message: text,
 							},
 						};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
typeof parsed === "object" && parsed !== null
? (parsed as Record<string, unknown>)
: {
body =
typeof parsed === "object" &&
parsed !== null &&
!Array.isArray(parsed)
? (parsed as Record<string, unknown>)
: {
error: {
message: text,
},
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/gateway/src/videos/videos.ts` around lines 2719 - 2721, The object type
guard in the parsed-body condition is accepting arrays because typeof array
returns "object" in JavaScript, which causes array payloads to bypass the
fallback handler and be returned as Record<string, unknown>, violating the
intended response contract. Modify the guard expression that checks `typeof
parsed === "object" && parsed !== null` to additionally exclude arrays by adding
an Array.isArray check, ensuring only plain objects pass through while arrays
fall through to the fallback case.

error: {
message: text,
},
};
} catch {
body = {
error: {
Expand Down
Loading