-
Notifications
You must be signed in to change notification settings - Fork 573
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
harden datetime verification #1702
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cf90833
syntax: add datetime validator (and interop tests)
bnewbold 443ef1f
syntax: improve datetime normalization
bnewbold 1d6c337
lexicon: stronger datetime validation (from syntax package)
bnewbold bb9a0ed
syntax: make datetime syntax norm test more flexible
bnewbold 756aa57
make fmt
bnewbold a394556
datetime: docs, normalize and always variant
bnewbold d5e27d6
bsky replace toSimplifiedISOSafe with normalizeDatetimeAlways
bnewbold a52bdcc
Merge branch 'main' into bnewbold/harden-datetime
dholms 9220573
more rigorous datetime parsing on record creation
dholms eac065a
handle negative dates
dholms 91f5d93
syntax: disallow datetimes before year 0010
bnewbold 9f1c382
syntax: datetime normalization functions validate output
bnewbold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# superficial syntax parses ok, but are not valid datetimes for semantic reasons (eg, "month zero") | ||
1985-00-12T23:20:50.123Z | ||
1985-04-00T23:20:50.123Z | ||
1985-13-12T23:20:50.123Z | ||
1985-04-12T25:20:50.123Z | ||
1985-04-12T23:99:50.123Z | ||
1985-04-12T23:20:61.123Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
# subtle changes to: 1985-04-12T23:20:50.123Z | ||
1985-04-12T23:20:50.123z | ||
01985-04-12T23:20:50.123Z | ||
985-04-12T23:20:50.123Z | ||
1985-04-12T23:20:50.Z | ||
1985-04-32T23;20:50.123Z | ||
1985-04-32T23;20:50.123Z | ||
|
||
# en-dash and em-dash | ||
1985—04-32T23;20:50.123Z | ||
1985–04-32T23;20:50.123Z | ||
|
||
# whitespace | ||
1985-04-12T23:20:50.123Z | ||
1985-04-12T23:20:50.123Z | ||
1985-04-12T 23:20:50.123Z | ||
|
||
# not enough zero padding | ||
1985-4-12T23:20:50.123Z | ||
1985-04-2T23:20:50.123Z | ||
1985-04-12T3:20:50.123Z | ||
1985-04-12T23:0:50.123Z | ||
1985-04-12T23:20:5.123Z | ||
|
||
# too much zero padding | ||
01985-04-12T23:20:50.123Z | ||
1985-004-12T23:20:50.123Z | ||
1985-04-012T23:20:50.123Z | ||
1985-04-12T023:20:50.123Z | ||
1985-04-12T23:020:50.123Z | ||
1985-04-12T23:20:050.123Z | ||
|
||
# strict capitalization (ISO-8601) | ||
1985-04-12t23:20:50.123Z | ||
1985-04-12T23:20:50.123z | ||
|
||
# RFC-3339, but not ISO-8601 | ||
1985-04-12T23:20:50.123-00:00 | ||
1985-04-12_23:20:50.123Z | ||
1985-04-12 23:20:50.123Z | ||
|
||
# ISO-8601, but weird | ||
1985-04-274T23:20:50.123Z | ||
|
||
# timezone is required | ||
1985-04-12T23:20:50.123 | ||
1985-04-12T23:20:50 | ||
|
||
1985-04-12 | ||
1985-04-12T23:20Z | ||
1985-04-12T23:20:5Z | ||
1985-04-12T23:20:50.123 | ||
+001985-04-12T23:20:50.123Z | ||
23:20:50.123Z | ||
|
||
1985-04-12T23:20:50.123+00 | ||
1985-04-12T23:20:50.123+00:0 | ||
1985-04-12T23:20:50.123+0:00 | ||
1985-04-12T23:20:50.123 | ||
1985-04-12T23:20:50.123+0000 | ||
1985-04-12T23:20:50.123+00 | ||
1985-04-12T23:20:50.123+ | ||
1985-04-12T23:20:50.123- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# "preferred" | ||
1985-04-12T23:20:50.123Z | ||
1985-04-12T23:20:50.000Z | ||
2000-01-01T00:00:00.000Z | ||
1985-04-12T23:20:50.123456Z | ||
1985-04-12T23:20:50.120Z | ||
1985-04-12T23:20:50.120000Z | ||
|
||
# "supported" | ||
1985-04-12T23:20:50.1235678912345Z | ||
1985-04-12T23:20:50.100Z | ||
1985-04-12T23:20:50Z | ||
1985-04-12T23:20:50.0Z | ||
1985-04-12T23:20:50.123+00:00 | ||
1985-04-12T23:20:50.123-07:00 | ||
1985-04-12T23:20:50.123+07:00 | ||
1985-04-12T23:20:50.123+01:45 | ||
0985-04-12T23:20:50.123-07:00 | ||
1985-04-12T23:20:50.123-07:00 | ||
0123-01-01T00:00:00.000Z | ||
|
||
# various precisions, up through at least 12 digits | ||
1985-04-12T23:20:50.1Z | ||
1985-04-12T23:20:50.12Z | ||
1985-04-12T23:20:50.123Z | ||
1985-04-12T23:20:50.1234Z | ||
1985-04-12T23:20:50.12345Z | ||
1985-04-12T23:20:50.123456Z | ||
1985-04-12T23:20:50.1234567Z | ||
1985-04-12T23:20:50.12345678Z | ||
1985-04-12T23:20:50.123456789Z | ||
1985-04-12T23:20:50.1234567890Z | ||
1985-04-12T23:20:50.12345678901Z | ||
1985-04-12T23:20:50.123456789012Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import { defaultFetchHandler } from '@atproto/xrpc' | |
import * as Post from '../src/lexicon/types/app/bsky/feed/post' | ||
import { paginateAll } from './_util' | ||
import AppContext from '../src/context' | ||
import { ids } from '../src/lexicon/lexicons' | ||
import { ids, lexicons } from '../src/lexicon/lexicons' | ||
|
||
const alice = { | ||
email: '[email protected]', | ||
|
@@ -579,6 +579,24 @@ describe('crud operations', () => { | |
) | ||
}) | ||
|
||
it('validates datetimes more rigorously than lex sdk', async () => { | ||
const postRecord = { | ||
$type: 'app.bsky.feed.post', | ||
text: 'test', | ||
createdAt: '1985-04-12T23:20:50.123', | ||
} | ||
lexicons.assertValidRecord('app.bsky.feed.post', postRecord) | ||
await expect( | ||
aliceAgent.api.com.atproto.repo.createRecord({ | ||
repo: alice.did, | ||
collection: 'app.bsky.feed.post', | ||
record: postRecord, | ||
}), | ||
).rejects.toThrow( | ||
'Invalid app.bsky.feed.post record: createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601)', | ||
) | ||
}) | ||
|
||
describe('compare-and-swap', () => { | ||
let recordCount = 0 // Ensures unique cids | ||
const postRecord = () => ({ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
added the extra check here
This means records with bad timestamps will still pass "lexicon validation" (which we want so that old records don't break application views), but they will no longer be able to be created on the pds
this specific approach only works as is because the only datetimes on our records are
createdAt
times & everycreatedAt
property is a datetime. if we get other datetimes, we'll need to tweak this logic