-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bug: Domain only validation doesn't work for custom schemes #205
Merged
mattheworris
merged 13 commits into
main
from
200-bug-domain-only-validation-doesnt-work-for-custom-schemes
Oct 31, 2024
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11f837f
feat: initial implementation for updated URI/domain validation
mattheworris a332dc1
Merge branch 'main' into 200-bug-domain-only-validation-doesnt-work-f…
mattheworris 9312f42
Merge branch 'main' of github.com:ProjectLibertyLabs/siwf into 200-bu…
mattheworris c0f3043
Merge branch '200-bug-domain-only-validation-doesnt-work-for-custom-s…
mattheworris c85b0a3
fix: lint errors
mattheworris 4530b6d
refactor: update login message property name
mattheworris 6fb4c17
fix: lint
mattheworris 78044a5
refactor: update Request and RequestUrl JSON data
mattheworris 999b3bc
fix: tools/js-example tests broken: update
mattheworris 06f5b0d
fix: update ExamplePayloadLoginStatic and test cases
mattheworris f23fc87
fix: refactor validateDomainAndUri; add test for bad protocol
mattheworris 8528a49
fix: update docs to clarify domain must match uri
mattheworris f5fd375
fix: update data structures
mattheworris 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
```json | ||
{ | ||
"signedRequest": "eyJyZXF1ZXN0ZWRTaWduYXR1cmVzIjp7InB1YmxpY0tleSI6eyJlbmNvZGVkVmFsdWUiOiJmNmNMNHdxMUhVTngxMVRjdmRBQk5mOVVOWFhveUg0N21WVXdUNTl0elNGUlc4eURIIiwiZW5jb2R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4eURIIiwiZW5jb2RpbmciOiJiYXNlNTgiLCJmb3JtYXQiOiJzczU4IiwidHlwZSI6IlNyMjU1MTkifSwic2lnbmF0dXJlIjp7ImFsZ28iOiJTUjI1NTE5IiwiZW5jb2RpbmciOiJiYXNlMTYiLCJlbmNvZGVkVmFsdWUiOiIweDVjODZkMDk2NjAzNTkzZWZmNGMwYzAxM2VjY2E4NDdiZTUzMTczZTNhYTU2YTNiNWE3NzM0NDliNjE3NTA3MWNlYmNmNDM2YmVhZDcyMDgxNmU2YzE1YzMyZmExZTE0MWRkMzYzNDJjYjQ0ZmVkZjE1ODMzYTc5N2VhMjM5NjgzIn0sInBheWxvYWQiOnsiY2FsbGJhY2siOiJodHRwOi8vbG9jYWxob3N0OjMwMDAiLCJwZXJtaXNzaW9ucyI6WzUsNyw4LDksMTBdfX0sInJlcXVlc3RlZENyZWRlbnRpYWxzIjpbeyJ0eXBlIjoiVmVyaWZpZWRHcmFwaEtleUNyZWRlbnRpYWwiLCJoYXNoIjpbImJjaXFtZHZteGQ1NHp2ZTVraWZ5Y2dzZHRvYWhzNWVjZjRoYWwydHMzZWV4a2dvY3ljNW9jYTJ5Il19LHsiYW55T2YiOlt7InR5cGUiOiJWZXJpZmllZEVtYWlsQWRkcmVzc0NyZWRlbnRpYWwiLCJoYXNoIjpbImJjaXFlNHFvY3poZnRpY2k0ZHpmdmZiZWw3Zm80aDRzcjVncmNvM29vdnd5azZ5NHluZjQ0dHNpIl19LHsidHlwZSI6IlZlcmlmaWVkUGhvbmVOdW1iZXJDcmVkZW50aWFsIiwiaGFzaCI6WyJiY2lxanNwbmJ3cGMzd2p4NGZld2NlazVkYXlzZGpwYmY1eGppbXo1d251NXVqN2UzdnUydXducSJdfV19XX0", | ||
"mode": "dark" | ||
} | ||
``` |
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 |
---|---|---|
@@ -1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aGFzaCI6WyJiY2lxanNwbmJ3cGMzd2p4NGZld2NlazVkYXlzZGpwYmY1eGppbXo1d251NXVqN2UzdnUydXducSJdfV19XX0&mode=dark" | ||
``` |
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 |
---|---|---|
|
@@ -12,38 +12,52 @@ import { | |
serializeItemActionsPayloadHex, | ||
} from '../util.js'; | ||
|
||
function generateLoginMessage(account: string, issued: Date, expires: Date, domain: string) { | ||
return `${domain} wants you to sign in with your Frequency account:\n${account}\n\n\n\nURI: https://testnet.frequencyaccess.com/signin/confirm\nNonce: N6rLwqyz34oUxJEXJ\nIssued At: ${issued.toISOString()}\nExpiration Time: ${expires.toISOString()}`; | ||
function generateLoginMessage(account: string, issued: Date, expires: Date, uri: URL) { | ||
return `${uri.hostname} wants you to sign in with your Frequency account:\n${account}\n\n\n\nURI: ${uri}\nNonce: N6rLwqyz34oUxJEXJ\nIssued At: ${issued.toISOString()}\nExpiration Time: ${expires.toISOString()}`; | ||
} | ||
|
||
// Setup now so that it is consistent for the entire test run | ||
const now = Date.now(); | ||
|
||
const loginMessageGood = (domain: string) => | ||
const loginMessageUrl = (url: string) => | ||
generateLoginMessage( | ||
ExampleUserKey.public, | ||
new Date(now - 24 * 60 * 60 * 1000), | ||
new Date(now + 24 * 60 * 60 * 1000), | ||
domain | ||
new URL(url) | ||
); | ||
|
||
const loginMessageGood = () => loginMessageUrl('https://your-app.com/signin/callback'); | ||
|
||
const loginMessageExpired = () => | ||
generateLoginMessage( | ||
ExampleUserKey.public, | ||
new Date(now - 2 * 24 * 60 * 60 * 1000), | ||
new Date(now - 24 * 60 * 60 * 1000), | ||
'localhost' | ||
new URL('https://your-app.com/signin/callback') | ||
); | ||
|
||
export const ExamplePayloadLoginGood = (domain: string): SiwfResponsePayloadLogin => ({ | ||
export const ExamplePayloadLoginUrl = (url: string): SiwfResponsePayloadLogin => ({ | ||
signature: { | ||
algo: 'SR25519', | ||
encoding: 'base16', | ||
encodedValue: u8aToHex(ExampleUserKey.keyPair().sign(loginMessageUrl(url))), | ||
}, | ||
type: 'login', | ||
payload: { | ||
message: loginMessageUrl(url), | ||
}, | ||
}); | ||
|
||
export const ExamplePayloadLoginGood = (): SiwfResponsePayloadLogin => ({ | ||
signature: { | ||
algo: 'SR25519', | ||
encoding: 'base16', | ||
encodedValue: u8aToHex(ExampleUserKey.keyPair().sign(loginMessageGood(domain))), | ||
encodedValue: u8aToHex(ExampleUserKey.keyPair().sign(loginMessageGood())), | ||
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. domain will always match the URI in the test cases |
||
}, | ||
type: 'login', | ||
payload: { | ||
message: loginMessageGood(domain), | ||
message: loginMessageGood(), | ||
}, | ||
}); | ||
|
||
|
@@ -59,6 +73,7 @@ export const ExamplePayloadLoginExpired = (): SiwfResponsePayloadLogin => ({ | |
}, | ||
}); | ||
|
||
// TODO: This test case is broken because now the domain is extracted from the URL, so isn't localhost | ||
export const ExamplePayloadLoginStatic: SiwfResponsePayloadLogin = { | ||
signature: { | ||
algo: 'SR25519', | ||
|
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
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.
Allows to build test cases with different urls