mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-09-10 22:14:48 -05:00
feat(xo-server/createAuthenticationToken): throw if expiresIn is too high
This commit is contained in:
@@ -164,15 +164,18 @@ export default class {
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
async createAuthenticationToken({ expiresIn, userId }) {
|
||||
let duration = this._defaultTokenValidity
|
||||
if (expiresIn !== undefined) {
|
||||
duration = parseDuration(expiresIn)
|
||||
if (duration > this._maxTokenValidity) {
|
||||
throw new Error('too high expiresIn duration: ' + expiresIn)
|
||||
}
|
||||
}
|
||||
|
||||
const token = new Token({
|
||||
id: await generateToken(),
|
||||
user_id: userId,
|
||||
expiration:
|
||||
Date.now() +
|
||||
Math.min(
|
||||
expiresIn !== undefined ? parseDuration(expiresIn) : this._defaultTokenValidity,
|
||||
this._maxTokenValidity
|
||||
),
|
||||
expiration: Date.now() + duration,
|
||||
})
|
||||
|
||||
await this._tokens.add(token)
|
||||
|
||||
Reference in New Issue
Block a user