-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replay prevention for client assertions is now built in
This removes the need for a custom built `uniqueness` helper, instead it'll use the storage adapter to store values. This mechanism will be utilized by future DPoP feature.
- Loading branch information
Showing
11 changed files
with
72 additions
and
45 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const hash = require('object-hash'); | ||
const base64url = require('base64url'); | ||
|
||
const instance = require('../helpers/weak_cache'); | ||
const epochTime = require('../helpers/epoch_time'); | ||
|
||
const hasFormat = require('./mixins/has_format'); | ||
|
||
const fingerprint = properties => base64url(hash(properties, { | ||
ignoreUnknown: true, | ||
unorderedArrays: true, | ||
encoding: 'buffer', | ||
algorithm: 'sha256', | ||
})); | ||
|
||
module.exports = provider => class ReplayDetection extends hasFormat(provider, 'ReplayDetection', instance(provider).BaseModel) { | ||
static get IN_PAYLOAD() { | ||
return [ | ||
...super.IN_PAYLOAD, | ||
'iss', | ||
]; | ||
} | ||
|
||
static async unique(iss, jti, exp) { | ||
const id = fingerprint({ iss, jti }); | ||
|
||
const found = await this.find(id); | ||
|
||
if (found) { | ||
return false; | ||
} | ||
|
||
const inst = new this({ | ||
jti: id, | ||
exp, | ||
iss, | ||
}); | ||
|
||
await inst.save(exp - epochTime()); | ||
|
||
return true; | ||
} | ||
}; |
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