Skip to content

Add time, origin, and ip to request object#2263

Open
dwwoelfel wants to merge 7 commits intomainfrom
request.time
Open

Add time, origin, and ip to request object#2263
dwwoelfel wants to merge 7 commits intomainfrom
request.time

Conversation

@dwwoelfel
Copy link
Contributor

@dwwoelfel dwwoelfel commented Feb 6, 2026

Easier to review with whitespace turned off https://github.com/instantdb/instant/pull/2263/changes?w=1

Adds request.time, request.origin, and request.ip to the rules file.

The request.time is a cel timestamp. In order to make it easier to use, I added a .getTime function to timestamps that will return the value in milliseconds since the epoch (same as Date.getTime in javascript).

I also overrode the default timestamp function to accept anything that we accept as a date instead of just rfc 3339 strings.

The sandbox allows you to override ip and origin for testing.

To set the ip and origin, I put them in a *request-info* dynamic binding. It's set in http middleware to catch any admin requests, and then it's set in handle-receive from the socket-ip and the socket-origin.

I upgraded cel and added the math extensions so that you could reasonably write rules protecting the updatedAt field. It looks like:

math.abs((request.time - timestamp(data.updatedAt)).getMinutes()) <= 1

Subtracting timestamps creates a duration, which you can call getMinutes on, then math.abs gets you within either side of the 1 minute of leeway.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

View Vercel preview at instant-www-js-request-time-jsv.vercel.app.

Copy link
Contributor

@nezaj nezaj left a comment

Choose a reason for hiding this comment

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

Woohoo! Did we want to include docs with this or put that in a separate PR?

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