-
Notifications
You must be signed in to change notification settings - Fork 133
axiom plugin #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
axiom plugin #110
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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; | ||
| }); |
There was a problem hiding this comment.
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.
No description provided.