fetch() SSL disable certificate validation #4636
Answered
by
KhafraDev
marek-benes
asked this question in
Q&A
|
Hello, is there any way to disable SSL certificate validation for self-signed certificates or expired ones? Thank you. |
Answered by
KhafraDev
Apr 23, 2023
Replies: 0 comments 29 replies
|
Yes, pass |
3 replies
|
use this in your fetch const https = require('https'); // or import https from 'https'
const agent = new https.Agent({
rejectUnauthorized: false,
});
fetch("https://google.com", { method: "get", body: body, agent }); |
13 replies
|
Obviously on localhost it's a matter of CORS |
0 replies
|
Using the built in fetch with undici, you can do import { Agent, setGlobalDispatcher } from 'undici'
const agent = new Agent({
connect: {
rejectUnauthorized: false
}
})
setGlobalDispatcher(agent)
await fetch('...') |
6 replies
Answer selected by
marek-benes
|
For anyone looking to do this without dependencies, e.g. for scripting use: #!/usr/bin/env -S node --no-warnings
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
await fetch("https://localhost");The lengths one has to go through with built-in |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Using the built in fetch with undici, you can do