govuk-one-login / ipv-cri-common-express

Common frontend components for Credential Issuers
MIT License
2 stars 0 forks source link

OJ-2724: Show the error page if the `redirect_uri` is not set/`authParams` is undefined #398

Closed surajkumar closed 2 months ago

surajkumar commented 2 months ago

Proposed changes

Have been advised by Lime team to release this as a breaking change as they are uncertain of the impact it may have.

What changed

error-handling.js added check to see if the redirect_uri is present within redirectAsErrorToCallback method and redirect_uri is undefined then display the error page.

Why did it change

CRI's were getting the following error message: Cannot read properties of undefined (reading 'redirect_uri') and this was causing users to not go to an appropriate error screen.

Some teams were adding a fix to their own frontends but given it's happening everywhere, it's better to fix it here.

Full error message:

{"@timestamp":"2024-08-19T14:56:19.443Z","level":"ERROR","message":"10.1.60.167 - /search Cannot read properties of undefined (reading 'redirect_uri')","sessionID":"<>","method":"GET","host":"ip-10-1-50-249.eu-west-2.compute.internal","label":"hmpo-app:hmpo-app","stack":["TypeError: Cannot read properties of undefined (reading 'redirect_uri')","    at redirectAsErrorToCallback (/app/node_modules/@govuk-one-login/di-ipv-cri-common-express/src/lib/error-handling.js:13:47)","    at newFn (/app/node_modules/express-async-errors/index.js:16:20)","    at Layer.handle_error (/app/node_modules/express/lib/router/layer.js:71:5)","    at d.runFunctionInContext (/opt/dynatrace/oneagent/agent/bin/1.295.66.20240805-161707/any/nodejs/nodejsagent.js:2589:80)","    at d.runFunction (/opt/dynatrace/oneagent/agent/bin/1.295.66.20240805-161707/any/nodejs/nodejsagent.js:2577:19)","    at Layer.handle_error (/opt/dynatrace/oneagent/agent/bin/1.295.66.20240805-161707/any/nodejs/nodejsagent.js:8879:18)","    at trim_prefix (/app/node_modules/express/lib/router/index.js:326:13)","    at /app/node_modules/express/lib/router/index.js:286:9","    at Function.process_params (/app/node_modules/express/lib/router/index.js:346:12)","    at Immediate.next (/app/node_modules/express/lib/router/index.js:280:10)"],"request":"/search","template":"errors/error"}

After:

{"@timestamp":"2024-08-20T10:15:00.130Z","level":"ERROR","message":"127.0.0.1 - /kbv/question Missing redirect_uri","sessionID":"Hw62cF4o8N4MINvqvMlBmCvruNpj-knQ","method":"GET","host":"NZXT","label":"hmpo-app:hmpo-app","stack":["Error: Missing redirect_uri","    at redirectAsErrorToCallback (/home/ubuntu/IdeaProjects/ipv-cri-common-express/src/lib/error-handling.js:29:19)","    at newFn (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express-async-errors/index.js:16:20)","    at Layer.handle_error (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/layer.js:71:5)","    at trim_prefix (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/index.js:326:13)","    at /home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/index.js:286:9","    at Function.process_params (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/index.js:346:12)","    at Immediate.next (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/index.js:280:10)","    at Immediate.<anonymous> (/home/ubuntu/IdeaProjects/ipv-cri-kbv-front/node_modules/express/lib/router/index.js:646:15)","    at process.processImmediate (node:internal/timers:478:21)"],"request":"/kbv/question","template":"errors/error"}

Issue tracking

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud