# Npm sonarqube-scanner fails behind proxy

**URL:** <https://community.sonarsource.com/t/npm-sonarqube-scanner-fails-behind-proxy/130094>\
**Category:** SonarQube Server / Community Build\
**Tags:** bug, sonar-scanner, scanner\
**Created:** [November 9, 2024, 6:55am UTC](https://community.sonarsource.com/t/npm-sonarqube-scanner-fails-behind-proxy/130094 "2024-11-09T06:55:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicotu01](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nicotu01/32/63968_2.png) [@nicotu01](https://community.sonarsource.com/u/nicotu01)\
**Post date:** [November 9, 2024, 6:55am UTC](https://community.sonarsource.com/t/npm-sonarqube-scanner-fails-behind-proxy/130094/1 "2024-11-09T06:55:27Z")

</div>

Hi !  
I’m using the npm library sonarqube-scanner version 4.2.5 with an http proxy and it results on a HTTP 403 error when fetching the api.

My proxy configuration is set by environment variable : `export HTTP_PROXY=http://my-proxy:3128`.  
When I invoke the scan function, it fails on first call to sonarqube API.

After investigation, I found that this is due to the way the axios http client is instantiated.

In axios documentation ([Request Config | Axios Docs](https://axios-http.com/docs/req_config)), it’s specify that proxy has to be set to false when supplying an httpAgent:

```auto
// Use `false` to disable proxies, ignoring environment variables.
// Disable if supplying a custom httpAgent/httpsAgent to manage proxying requests.
proxy: {

```

Is it possible to disable the `proxy` option when using an httpAgent ?

Ex in file `request.ts`, function `getHttpAgents` :  
replace :

```auto
  return agents;

```

by

```auto
  return {...agents, ...((agents.httpsAgent || agents.httpAgent) ? {proxy:false} : {})};

```

Here, minimalist code to reproduce :

```auto
import axios from "axios";
import hpagent from "hpagent";

process.env.HTTP_PROXY = 'http://localhost:3128'
axios
  .get("http://sonarqube-ic.intra.arkea.com:8080/api/server/version", {
    httpAgent: new hpagent.HttpProxyAgent({ proxy: "http://localhost:3128" })
  })
  .then((res) => {
    console.log(res);
  })
  .catch((err) => console.error(err));

```

This request returns a 403 because axios configures 2 proxies

---

<div class="post-metadata">

**Author:** ![benjamin.raymond](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/benjamin.raymond/32/41399_2.png) [@benjamin.raymond](https://community.sonarsource.com/u/benjamin.raymond)\
**Post date:** [November 14, 2024, 2:31pm UTC](https://community.sonarsource.com/t/npm-sonarqube-scanner-fails-behind-proxy/130094/4 "2024-11-14T14:31:08Z")

</div>

Hello @nicotu01 ,

After running some tests and investigating the issue, we could conclude that your assessment is correct: When `HTTP[S]_PROXY` environment variables are set, axios will try and connect to the proxy directly even though we are setting the `http[s]Agent` options.

I’ve summarized the problem and fix in a ticket [SCANNPM-58](https://sonarsource.atlassian.net/browse/SCANNPM-58) which you can use to track our progress.

Thanks for reporting
