Skip to content

Commit

Permalink
ADOP-2488: Fix fortify open-redirect issues (#1583)
Browse files Browse the repository at this point in the history
* test moving checks to be on req.query.lang not temp var

* move the &&s

* Spacing

* use array.find to ensure redirect urls/query params are part of whitelist

* add request url

* fix issues

* linting issues

* mock secret

* semicolon...
  • Loading branch information
DanCatchpole authored Oct 1, 2024
1 parent 4f1c187 commit 62a1f31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/app/controller/GetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export class GetController {
if (callback) {
callback();
} else {
res.redirect(req.url);
const redirectUrl = Object.values(Urls).find(item => item === req.url);
res.redirect(redirectUrl ?? Urls.HOME_URL);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/kba/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class KbaMiddleware {
let param = '';
const supportedLang = ['en', 'cy'];
if (langCode !== null && supportedLang.includes(langCode as string)) {
param = '?lang=' + langCode;
param = '?lang=' + supportedLang.find(item => item === langCode);
}
if (req.session.laPortalKba?.kbaCaseRef) {
req.session.user = await getSystemUser();
Expand Down
7 changes: 4 additions & 3 deletions src/main/modules/session/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jest.mock('config');
const mockCreateClient = jest.fn(() => 'MOCK redis client');
const mockSecret = jest.fn(() => 'mock-secret');

jest.mock('redis', () => {
return {
Expand Down Expand Up @@ -48,7 +49,7 @@ describe('session', () => {
let mockApp;

beforeEach(() => {
config.get = jest.fn().mockImplementationOnce(() => 'MOCK_SECRET');
config.get = jest.fn().mockImplementationOnce(() => mockSecret);
mockApp = {
locals: {
developmentMode: false,
Expand All @@ -68,7 +69,7 @@ describe('session', () => {
name: 'adoption-web-session',
resave: false,
saveUninitialized: false,
secret: 'MOCK_SECRET',
secret: mockSecret,
cookie: {
httpOnly: true,
maxAge: 1260000,
Expand All @@ -84,7 +85,7 @@ describe('session', () => {
beforeEach(() => {
config.get = jest
.fn()
.mockImplementationOnce(() => 'MOCK_SECRET')
.mockImplementationOnce(() => mockSecret)
.mockImplementationOnce(() => 'true')
.mockImplementationOnce(() => 'MOCK_REDIS_HOST')
.mockImplementationOnce(() => 'MOCK_REDIS_KEY');
Expand Down
2 changes: 2 additions & 0 deletions src/main/steps/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,5 @@ export const LA_PORTAL_CONTACT_US: PageLink = `${LA_PORTAL}/contact-us`;
export const LA_PORTAL_CHECK_YOUR_ANSWERS: PageLink = `${LA_PORTAL}/check-your-answers`;
export const LA_PORTAL_STATEMENT_OF_TRUTH: PageLink = `${LA_PORTAL}/statement-of-truth`;
export const LA_PORTAL_CONFIRMATION_PAGE: PageLink = `${LA_PORTAL}/confirmation`;

export const TEST_REQUEST: PageLink = '/request'; // todo - remove this and update generic tests to use a valid URL

0 comments on commit 62a1f31

Please sign in to comment.