-
Notifications
You must be signed in to change notification settings - Fork 234
fix: reject expiration timestamp 0 and accept far-future timestamps in getEventExpiration() #708
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?
Changes from all commits
b2df8e4
7b7761a
14b57b6
3457bae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "nostream": patch | ||
| --- | ||
|
|
||
| fix: reject expiration timestamp 0 and millisecond-scale values, and accept safe-integer second-based timestamps up to year 9999 in getEventExpiration() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -691,6 +691,26 @@ describe('NIP-40', () => { | |
| event.tags = [['expiration', 'a']] | ||
| expect(getEventExpiration(event)).to.be.undefined | ||
| }) | ||
|
|
||
| it('returns false if expiration is 0', () => { | ||
| event.tags = [['expiration', '0']] | ||
| expect(getEventExpiration(event)).to.be.undefined | ||
| }) | ||
|
|
||
| it('returns true if expiration is a safe integer beyond year 2287', () => { | ||
| event.tags = [['expiration', '10000000000']] | ||
| expect(getEventExpiration(event)).to.equal(10000000000) | ||
| }) | ||
|
|
||
| it('returns true if expiration is the maximum representable Unix seconds timestamp', () => { | ||
| event.tags = [['expiration', '253402300799']] | ||
| expect(getEventExpiration(event)).to.equal(253402300799) | ||
| }) | ||
|
|
||
| it('returns false if expiration looks like a millisecond-scale timestamp', () => { | ||
| event.tags = [['expiration', '1700000000000']] | ||
| expect(getEventExpiration(event)).to.be.undefined | ||
| }) | ||
| }) | ||
|
|
||
| describe('isExpiredEvent', () => { | ||
|
Comment on lines
691
to
716
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a problem with the new ceiling though.
The On The tests only exercise the validation function and never hit the database, so there wasn't really a way for this to be caught by the current test suite. It's an easy thing to miss. |
||
|
|
||
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.
Thanks for the PR! The
Math.log10(0)fix is a genuine improvement.