Skip to content

Conversation

@ctate
Copy link
Collaborator

@ctate ctate commented Dec 2, 2025

No description provided.

@vercel
Copy link
Contributor

vercel bot commented Dec 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
workflow-builder Ready Ready Preview Comment Dec 2, 2025 9:05am

Comment on lines +56 to +80
const parsed = JSON.parse(input.events) as unknown;
// Support both single object and array
events = Array.isArray(parsed) ? parsed : [parsed];
} catch {
return {
success: false,
error:
"Invalid JSON in events field. Expected an array of objects or a single object.",
};
}

if (events.length === 0) {
return {
success: false,
error: "No events to ingest. Events array is empty.",
};
}

// Add timestamp to events that don't have one
const eventsWithTimestamp = events.map((event) => {
if (!event._time && !event.timestamp) {
return { ...event, _time: new Date().toISOString() };
}
return event;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The JSON parsing logic doesn't validate that the parsed value is an object before wrapping primitives in an array, causing data loss when users provide invalid JSON like "123" or "hello".

View Details
📝 Patch Details
diff --git a/plugins/axiom/steps/ingest-events.ts b/plugins/axiom/steps/ingest-events.ts
index 126c791..9760a0a 100644
--- a/plugins/axiom/steps/ingest-events.ts
+++ b/plugins/axiom/steps/ingest-events.ts
@@ -54,6 +54,16 @@ async function stepHandler(
     let events: Array<Record<string, unknown>>;
     try {
       const parsed = JSON.parse(input.events) as unknown;
+      
+      // Validate that parsed is an object or array of objects
+      if (parsed === null || typeof parsed !== "object") {
+        return {
+          success: false,
+          error:
+            "Invalid JSON in events field. Expected an array of objects or a single object.",
+        };
+      }
+      
       // Support both single object and array
       events = Array.isArray(parsed) ? parsed : [parsed];
     } catch {

Analysis

JSON parsing in ingestEventsStep() accepts primitives, causing data loss

What fails: The stepHandler() function in plugins/axiom/steps/ingest-events.ts accepts primitive values (numbers, strings, booleans, null) from JSON.parse() and wraps them in arrays without validation. When these primitives are later spread as objects ({ ...primitive, _time: "..." }), the primitive data is lost and only the timestamp is sent to the Axiom API.

How to reproduce:

// Call ingestEventsStep with primitive JSON values:
await ingestEventsStep({
  dataset: "test",
  events: "123"  // or "true", or "null", or '"hello"'
});

Result: Function returns { success: true, ingested: 1, ... } with events containing only { _time: "2025-12-02T..." } and no actual event data. The API receives events with missing data.

Expected behavior: Function should return { success: false, error: "Invalid JSON in events field. Expected an array of objects or a single object." } because primitives are not valid event objects.

The fix adds validation after JSON.parse() to reject primitives and null values before they are wrapped and processed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants