Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable SSL in Axios

is there an easy way to disable SSL validation in Axios. I tried this process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; but it doesn't work.

Here's an example of my code"

const postPosts = () => {
  axios
    .post("https://xxx.dev.lab", {
      Username: "xxx",
      Password: "xxx"
    })
    .then(response => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    });
};
postPosts();
like image 920
user1513388 Avatar asked Oct 16 '25 10:10

user1513388


1 Answers

Axios doesn't address that situation so far - you can try:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

BUT THATS A VERY BAD IDEA since it disables SSL across the whole node server..

or you can configure axios to use a custom agent and set rejectUnauthorized to false for that agent as mentioned here

example:

// At instance level
const instance = axios.create({
  httpsAgent: new https.Agent({  
    rejectUnauthorized: false
  })
});

instance.get('https://something.com/foo');

// At request level
 const agent = new https.Agent({  
 rejectUnauthorized: false
});

axios.get('https://something.com/foo', { httpsAgent: agent });
like image 150
Athish Murugan Avatar answered Oct 17 '25 23:10

Athish Murugan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!