Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Validate updatedAt on saves and deletes #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hstove
Copy link
Collaborator

@hstove hstove commented Nov 19, 2019

Fixes #29

Radiks-server was not properly validating the updatedAt attribute for model updates and deletes. This could potentially lead to signature jacking. Radiks-server now validated that the updatedAt field is greater than previous updatedAts. This acts similarly to an nonce in blockchains.

return true;
}
if (typeof this.previous.updatedAt !== "number") {
errorMessage("This model's previous `updatedAt` is not a number");

Choose a reason for hiding this comment

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

The errorMessage function call resulting in a thrown Error is a surprising side-effect that made this diff hard to reason about. I'd recommend something more like

throw createError('...')

@zone117x
Copy link

@hstove I read through the diff -- the code looks good and it appears to fix the issue. However, I have little understanding of the general codebase, and definitely don't have the a grasp on the functional end-to-end workings of Radiks needed to really understand the security model.

Is there anything in particular you want reviewed or tested? Otherwise, if you feel confident in the fixes, then I think we should go ahead and merge & release.

signature,
updatedAt,
}: { signature: string; updatedAt: string } = req.query;
if (!updatedAt || parseInt(updatedAt, 10) <= attrs.updatedAt) {

Choose a reason for hiding this comment

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

This may be an ignorant question --
I can't tell if the signature validation encompasses this updatedAt value, is the value from the client already validated before this function?
As in, is there a server-side component preventing a malicious client from just setting this value to Number.MAX_SAFE_INTEGER or something like that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no such check for updatedAt. We should add a validator check that the value is near the server's time.

@stackatron stackatron assigned hstove and reedrosenbluth and unassigned hstove Dec 5, 2019
@reedrosenbluth reedrosenbluth removed their assignment Apr 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete API needs to check for an updated updatedAt attribute
4 participants