Skip to content
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

fix: #EXUI-2079: Upgrade dependencies with moderate severity vulnerabilities #252

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1bca96a
fix: #EXUI-2531: Update yarn and node version for rpx-xui-node-lib
MunishSharmaHMCTS Nov 6, 2024
ae851c1
missing changes for actions in yml files
MunishSharmaHMCTS Nov 6, 2024
094fa84
missing changes
MunishSharmaHMCTS Nov 6, 2024
caf9f9d
missing changes
MunishSharmaHMCTS Nov 6, 2024
a192107
enable corepack
MunishSharmaHMCTS Nov 6, 2024
73fa8df
Enable corepack step added
MunishSharmaHMCTS Nov 6, 2024
70a661d
change for enabling corepack
MunishSharmaHMCTS Nov 6, 2024
5d154f5
enable corepack for package creation
MunishSharmaHMCTS Nov 7, 2024
1c18649
package version update
MunishSharmaHMCTS Nov 7, 2024
dc1bb2c
enable corepack in npmpublish
MunishSharmaHMCTS Nov 7, 2024
c7dc739
yarn 4 publish change
MunishSharmaHMCTS Nov 7, 2024
49194df
missing yarn npm publish
MunishSharmaHMCTS Nov 7, 2024
dbe0232
changed from yarn npm publish to npm publish
MunishSharmaHMCTS Nov 7, 2024
f4269cb
version update
MunishSharmaHMCTS Nov 7, 2024
d01ba80
#EXUI-2079: Upgrade dependencies with moderate severity vulnerabilities
MunishSharmaHMCTS Nov 7, 2024
f7f5cbf
eslint fix
MunishSharmaHMCTS Nov 7, 2024
7be331c
changes the import format for csrf
MunishSharmaHMCTS Nov 8, 2024
d3ecc43
eslint fix
MunishSharmaHMCTS Nov 8, 2024
0675a8c
reverting openid package change
MunishSharmaHMCTS Nov 12, 2024
2ddfb2c
further changes for failing tests
MunishSharmaHMCTS Nov 13, 2024
7b81ef2
Merge commit '99070699f3a777a073e336c2cfb5e20ad99822f2' into EXUI-207…
MunishSharmaHMCTS Nov 13, 2024
50aa32f
openid-client update
MunishSharmaHMCTS Nov 13, 2024
c12d985
yarn update
MunishSharmaHMCTS Nov 14, 2024
2d71a3a
Merge commit '37cdd22718aaaca25b74d97230cfaab36cee62d3' into EXUI-207…
MunishSharmaHMCTS Nov 14, 2024
afd56bb
keepSessionInfo is set to true to reserve the session info
MunishSharmaHMCTS Nov 21, 2024
32173c3
logout changes
MunishSharmaHMCTS Nov 21, 2024
27f3d19
failing test fix
MunishSharmaHMCTS Nov 21, 2024
66e2616
lint issue
MunishSharmaHMCTS Nov 21, 2024
3ce55bd
keepSessionInfo has been added to openid authenticate
MunishSharmaHMCTS Nov 25, 2024
ba69ff5
openid-client package updated
MunishSharmaHMCTS Nov 26, 2024
f710cdc
reverting openid client package upgrade
MunishSharmaHMCTS Nov 26, 2024
a6d4f31
ran yarn lint
MunishSharmaHMCTS Nov 26, 2024
c2f0a87
file version upgraded 2.29.5-exui-2079-without-openid-client-upgrade-…
MunishSharmaHMCTS Nov 26, 2024
14995a3
changes for right token issuer
MunishSharmaHMCTS Nov 28, 2024
c622c9b
Merge commit '57c9c9e7525216987029208db9786e2824726bc6' into EXUI-207…
MunishSharmaHMCTS Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-node-lib",
"version": "2.29.6",
"version": "2.29.5-exui-2079-rc13",
"description": "Common nodejs library components for XUI",
"main": "dist/index",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.1.0",
"@types/connect-redis": "^0.0.23",
"@types/csurf": "^1.9.36",
"@types/csurf": "^1.11.0",
"@types/debug": "^4.1.5",
"@types/express": "^4.17.2",
"@types/express-session": "1.17.10",
Expand Down Expand Up @@ -86,22 +86,22 @@
}
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"@dr.pogodin/csurf": "^1.14.0",
"axios": "^1.7.7",
"caller-path": "^3.0.0",
"connect-redis": "^4.0.4",
"csurf": "^1.11.0",
"debug": "^4.3.7",
"deepmerge": "^4.2.2",
"express": "^4.20.0",
"express-session": "^1.17.0",
"jest-mock-axios": "^4.7.3",
"jest-ts-auto-mock": "^2.1.0",
"joi": "^17.13.3 ",
"jwt-decode": "^2.2.0",
"openid-client": "^3.10.0",
"openid-client": "^5.7.1",
"otplib": "^12.0.1",
"passport": "^0.5.3",
"passport-oauth2": "^1.5.0",
"passport": "^0.7.0",
"passport-oauth2": "^1.8.0",
"redis": "^3.0.2",
"session-file-store": "^1.5.0",
"ts-auto-mock": "^3.5.0",
Expand Down
46 changes: 25 additions & 21 deletions src/auth/models/strategy.class.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as events from 'events'
import { NextFunction, Request, RequestHandler, Response, Router } from 'express'
import passport from 'passport'
import passport, { LogOutOptions } from 'passport'
import { AUTH } from '../auth.constants'
import jwtDecode from 'jwt-decode'
import { arrayPatternMatch, http, XuiLogger, getLogger } from '../../common'
import { AuthOptions } from './authOptions.interface'
import Joi from '@hapi/joi'
import Joi from 'joi'
import * as URL from 'url'
import { generators } from 'openid-client'
import csrf from 'csurf'
import csrf from '@dr.pogodin/csurf'
import { MySessionData } from './sessionData.interface'

export abstract class Strategy extends events.EventEmitter {
Expand Down Expand Up @@ -91,7 +91,6 @@ export abstract class Strategy extends events.EventEmitter {
/* istanbul ignore next */
public loginHandler = async (req: Request, res: Response, next: NextFunction): Promise<RequestHandler> => {
this.logger.log('Base loginHandler Hit')

const reqSession = req.session as MySessionData

// we are using oidc generator but it's just a helper, rather than installing another library to provide this
Expand Down Expand Up @@ -122,6 +121,7 @@ export abstract class Strategy extends events.EventEmitter {
{
redirect_uri: reqSession?.callbackURL,
state,
keepSessionInfo: true,
} as any,
(error: any, user: any, info: any) => {
/* istanbul ignore next */
Expand Down Expand Up @@ -167,7 +167,7 @@ export abstract class Strategy extends events.EventEmitter {
}

/* istanbul ignore next */
public logout = async (req: Request, res: Response): Promise<void> => {
public logout = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const reqSession = req.session as MySessionData

try {
Expand All @@ -188,22 +188,24 @@ export abstract class Strategy extends events.EventEmitter {
})

//passport provides this method on request object
req.logout((err) => {
console.error(err)
})
await this.destroySession(req)
/* istanbul ignore next */
if (req.query.noredirect) {
res.status(200).send({ message: 'You have been logged out!' })
return Promise.resolve()
}

const redirect = req.query.redirect ? req.query.redirect : AUTH.ROUTE.LOGIN
this.logger.log('redirecting to => ', redirect)
// 401 is when no accessToken
res.redirect(redirect as string)
req.logout({ keepSessionInfo: true }, async (err) => {
if (err) {
console.error(err)
return next(err)
}
await this.destroySession(req)
/* istanbul ignore next */
if (req.query.noredirect) {
res.status(200).send({ message: 'You have been logged out!' })
return Promise.resolve()
}

/* istanbul ignore next */
const redirect = req.query.redirect ? req.query.redirect : AUTH.ROUTE.LOGIN
this.logger.log('redirecting to => ', redirect)
// 401 is when no accessToken
res.redirect(redirect as string)
/* istanbul ignore next */
})
} catch (e) {
this.logger.error('error => ', e)
res.status(401).redirect(AUTH.ROUTE.DEFAULT_REDIRECT)
Expand Down Expand Up @@ -284,6 +286,8 @@ export abstract class Strategy extends events.EventEmitter {
this.strategyName,
{
redirect_uri: reqSession?.callbackURL,
keepSessionInfo: true,
failureMessage: true,
} as any,
(error: any, user: any, info: any) => {
const errorMessages: string[] = []
Expand Down Expand Up @@ -410,7 +414,7 @@ export abstract class Strategy extends events.EventEmitter {
this.logger.error(
`User has no application access, as they do not have a role that matches ${this.options.allowRolesRegex}.`,
)
return this.logout(req, res)
return this.logout(req, res, next)
}
if (!this.listenerCount(AUTH.EVENT.AUTHENTICATE_SUCCESS)) {
this.logger.log(
Expand Down
5 changes: 3 additions & 2 deletions src/auth/oidc/models/openid.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { oidc, OpenID } from './openid.class'
import passport from 'passport'
import express, { Request, response, Response, Router } from 'express'
import express, { NextFunction, Request, response, Response, Router } from 'express'
import { AUTH } from '../../auth.constants'
import { Client, Issuer, Strategy, TokenSet, UserinfoResponse } from 'openid-client'
import { createMock } from 'ts-auto-mock'
Expand Down Expand Up @@ -466,6 +466,7 @@ xtest('makeAuthorization() Should make an authorisation string', async () => {
xtest('strategy logout', async () => {
const session = createMock<MySessionData>()
const mockRequest = createMock<Request>()
const mockNextFunction = createMock<NextFunction>()
session.passport = {
user: {
tokenset: {
Expand All @@ -486,7 +487,7 @@ xtest('strategy logout', async () => {
mockResponse.redirect = jest.fn()
const spyhttp = jest.spyOn(http, 'delete').mockImplementation(() => Promise.resolve({} as any))
const spySessionDestroy = jest.spyOn(oidc, 'destroySession').mockImplementation(() => Promise.resolve({} as any))
await oidc.logout(mockRequest, mockResponse)
await oidc.logout(mockRequest, mockResponse, mockNextFunction)
expect(spyhttp).toHaveBeenCalled()
expect(spySessionDestroy).toHaveBeenCalled()
})
Expand Down
3 changes: 2 additions & 1 deletion src/auth/oidc/models/openid.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export class OpenID extends AuthStrategy {
const issuer = await this.discoverIssuer()

const metadata = issuer.metadata
metadata.issuer = this.options.issuerURL

this.logger.log('discover metadata', metadata)

Expand Down Expand Up @@ -256,6 +255,8 @@ export class OpenID extends AuthStrategy {
redirect_uri: reqsession?.callbackURL,
nonce,
state,
keepSessionInfo: true,
failureMessage: true,
} as any,
(error: any, user: any, info: any) => {
this.logger.log('passport authenticate')
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"transform": "ts-auto-mock/transformer",
"cacheBetweenTests": false
}
]
],
"noImplicitAny": false
},
"include": ["typings.d.ts", "src"],
"exclude": ["node_modules", "**/*.spec.ts"]
Expand Down
Loading