Skip to content

Commit

Permalink
fix: redirection token expiration check
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel committed Oct 6, 2023
1 parent 1b30f38 commit 69b8a2b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/server/webserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,15 @@ export class WebServer {
// verify JWT
try {
const valid = this.jws.verify(info.req.headers['sec-websocket-protocol'], 'HS256', Environment.Config.jwt_secret)
if (!valid) {
return false
const decodedToken = this.jws.decode(info.req.headers['sec-websocket-protocol'])
const currentTimestamp = Math.floor(Date.now() / 1000); // Current timestamp in seconds

if (!valid || !(decodedToken.payload.exp && decodedToken.payload.exp > currentTimestamp)) {
logger.error('Redirection token invalid')
return false // reject connection if problem with verify
}
} catch (err) { // reject connection if problem with verify
return false
} catch (error) {
logger.error(`Error verifying the token: ${error.message}`)
}
// Test if device has an established KVM session
const startIndex = info.req.url.indexOf('host=')
Expand Down

0 comments on commit 69b8a2b

Please sign in to comment.