Unable to connect secure endpoint using self signed certificate using custom Insomnia Plugin (net::ERR_CERT_AUTHORITY_INVALID)
- Dominant language
- TypeScript
- Stars
- 40k
- Forks
- 2.4k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 61
Description
I am trying to develop a plugin which will connect a website using client-certificate, fetch a token and add to the request context. The node js that I have written for this works fine when executed standalone. However, from Insomnia the request is failing with an error saying `net::ERR_CERT_AUTHORITY_INVALID`
**To Reproduce**
Import the plugin folder and reload to activate.
Trigger an API request and monitor the devtools console.
**Example Code**
`main.js`:
```javascript
const https = require('https');
const fs = require('fs');
const axios = require('axios').default;
module.exports.requestHooks = [
async function (context) {
try {
const agent = new https.Agent({
pfx: fs.readFileSync(keyStorePath),
passphrase: keyStorePassword,
ca: fs.readFileSync(keyStorePem)
});
const config = {
url: tokenUrl,
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
httpsAgent: agent,
data: {},
timeout: 5000
};
const response = await axios(config);
console.log("Response data:", response.data);
} catch (err) {
console.error("Request failed", err);
}
}
];
```
`package.json`:
```
{
"name": "insomnia-plugin-ma-secure-request",
"version": "0.0.1",
"description": "",
"private": true,
"author": "me",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"uuid": "^8.3.2"
},
"insomnia": {
"name": "ma-secure-request",
"description": ""
},
"main": "main.js"
}
```
**Expected behavior**
The token should be successfully fetched without throwing any error.
**Error logs**
```
/Users/myself/Library/Application Support/Insomnia/plugins/insomnia-plugin-ma-secure-request/node_modules/axios/lib/adapters/xhr.js:177 POST net::ERR_CERT_AUTHORITY_INVALID
```
```
Request failed Error: Network Error
at createError (VM1709 createError.js:16)
at XMLHttpRequest.handleError (VM1707 xhr.js:84)
```
**Desktop (please complete the following information):**
- OS: macOS 10.15.7
- Installation Method: homebrew
- App Version: 2021.4.1
I have executed the code separately outside Insomnia to ensure it works.
Contributor guide
Research direction
Start with the plugin's main.js request hook and package.json, then reproduce the request while monitoring the Insomnia devtools console. Compare the standalone Node.js behavior with the axios request inside Insomnia and trace the reported xhr.js failure. Done means the hook fetches the token from the self-signed secure endpoint without net::ERR_CERT_AUTHORITY_INVALID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100