-
Notifications
You must be signed in to change notification settings - Fork 41
Replace custom random number generator with UUID #1845
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ThisIsMissEm
left a comment
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.
Looks good, the only change to make is the comment about return uuidv4().toString().substring("0.".length);
Though I would like to maybe wait a moment until Nic A.S. or @matthieubosquet can respond about the policy / matcher IRIs and why the format they are in is at all significant. I think ESS is actually even hashing these IRIs (I wasn't able to find anything in my pod that had an ACR that contained the strings we use in this code)
src/thing/thing.ts
Outdated
| return ( | ||
| Date.now().toString() + Math.random().toString().substring("0.".length) | ||
| ); | ||
| return uuidv4().toString().substring("0.".length); |
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.
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.
Ahh roger that!
src/access/acp_v2.ts
Outdated
| "_copy_without" + | ||
| `_${encodeURIComponent(actorRelationToExclude)}_${actorToExclude}` + | ||
| `_${Date.now()}_${Math.random()}`; | ||
| `_${uuidv4()}`; |
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.
I think all these identifiers for newIriSuffix can be removed, and we can just always generate a uuidv4() in each of createResourceMatcherFor and createResourcePolicyFor probably should just be the matcher IRI with the hash replaced with a uuid, rather than appending to the IRI.
e.g., the current implementation may be leaking information about the actor & the relationship in the policy or matcher IRI, when that value carries no significance, and it's really just a "makes the policy nice to read/look at"
Though that may be a wider refactor, so deferring to @NSeydoux
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.
So if I understand this comment better, we can replace lines 867-870 with
const newIriSuffix = uuidv4();
Is that correct?
Will wait for @NSeydoux response before pushing updates.
Beyond just changing the value to the code mentioned above, would we need to change anything else? Specifically, do we have code in other places that relies on having the "copy_without", "actorRelationToExclude" or "actorTo Exclude" in the IriSuffix?
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.
Beyond just changing the value to the code mentioned above, would we need to change anything else? Specifically, do we have code in other places that relies on having the "copy_without", "actorRelationToExclude" or "actorTo Exclude" in the IriSuffix?
as far as I can tell, no, and in fact, ESS will make those IRIs for subject/object opaque, so they won't be returned back as-is anyway
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.
There shouldn't be any hard-coded dependencies on the resource names, or reliance on any in-IRI semantics in the low-level API (we know there is some in the high-level API, but that's irrelevant here). I don't think ESS changes these IRIs, for instance when using the permissions app you can give a human-friendly name to a policy and it is persisted as-is. Finally, I think there isn't any information leak here: any user authorized to see the ACR in the first place would be able to see any actor mentioned in it, so it being embedded in an IRI doesn't add any information to what the resource already contains. It is really just for debug purpose.
All that said, it is a good practice to not have semantics in IRIs, so provided there isn't any reliance on this piece of logic, I think we can go forward with Emelia's suggestion and just use the uuid.
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.
I've also subsequently removed the rather brittle test for encoding hashes in the ACP IRIs, as we don't do that any more, and the only place this may come in is through existing IRIs maybe.
|
This looks good now with the irrelevant tests removed. 👍 |
a4e3dca to
0cb06ed
Compare

This PR replaces our custom random number generator with
uuid.Note: This PR introduces a new package
uuidto the codebase, which we have audited and is already used by our other SDKs