Skip to content

Uncaught exception raised by decodeURI results in a process crash #689

@martin-bucinskas

Description

@martin-bucinskas

Describe the bug
The usage of decodeURI in commons-server/src/libs/utils.ts may result in an uncaught exception raised, crashing the process.

/my-project/node_modules/@mockoon/commons-server/dist/cjs/libs/utils.js:108
            query: requestUrl ? decodeURI(requestUrl.search.slice(1)) : null,
                                ^

URIError: URI malformed
    at decodeURI (<anonymous>)
    at CreateTransaction (/my-project/node_modules/@mockoon/commons-server/dist/cjs/libs/utils.js:108:33)
    at ServerResponse.<anonymous> (/my-project/node_modules/@mockoon/commons-server/dist/cjs/libs/server.js:112:81)
    at ServerResponse.emit (events.js:400:28)
    at emitCloseNT (_http_server.js:820:8)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
...
npm ERR! Exit status 1
npm ERR! 
...

To Reproduce
Request sent with a query parameter containing a malformed URI.
See the HTTPie requests below.

http --follow --timeout 3600 GET 'localhost:3001/my-endpoint?test=%3C%%3D4242%20%%3E'

Or equivalent non encoded version

http --follow --timeout 3600 GET 'localhost:3001/my-endpoint?test=<%=4242 %>'

Expected behavior
The expected behaviour would be to handle the decodeURI exception in a try/catch statement and handle accordingly (either log as a warning or an error, and replace the malformed URI with either an empty string or a sanitised string.

Screenshots
N/A

Mockoon version:
1.18.1

OS / OS version:
N/A

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done (ready for next release)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions