Merge pull request #7716 from adamkingsbury/rejectUnauthorized

Reject unauthorized
This commit is contained in:
Rory Powell 2022-10-12 10:22:01 +01:00 committed by GitHub
commit 98b6629a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -31,6 +31,7 @@ export interface BearerAuthConfig {
export interface RestConfig {
url: string
rejectUnauthorized: boolean
defaultHeaders: {
[key: string]: any
}

View File

@ -8,6 +8,7 @@ function runServer() {
checkDevelopmentEnvironment()
fixPath()
// this will setup http and https proxies form env variables
process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = "false"
bootstrap()
require("./app")
}

View File

@ -14,6 +14,7 @@ import {
BearerAuthConfig,
} from "../definitions/datasource"
import { get } from "lodash"
import * as https from "https"
import qs from "querystring"
const fetch = require("node-fetch")
const { formatBytes } = require("../utilities")
@ -76,6 +77,11 @@ const SCHEMA: Integration = {
required: false,
default: {},
},
rejectUnauthorized: {
type: DatasourceFieldType.BOOLEAN,
default: true,
required: false,
},
legacyHttpParser: {
display: "Legacy HTTP Support",
type: DatasourceFieldType.BOOLEAN,
@ -218,8 +224,12 @@ class RestIntegration implements IntegrationBase {
}
}
// make sure the query string is fully encoded
const main = `${path}?${qs.encode(qs.decode(queryString))}`
if (queryString) {
// make sure the query string is fully encoded
queryString = "?" + qs.encode(qs.decode(queryString))
}
const main = `${path}${queryString}`
let complete = main
if (this.config.url && !main.startsWith("http")) {
complete = !this.config.url ? main : `${this.config.url}/${main}`
@ -381,6 +391,12 @@ class RestIntegration implements IntegrationBase {
paginationValues
)
if (this.config.rejectUnauthorized == false) {
input.agent = new https.Agent({
rejectUnauthorized: false,
})
}
if (this.config.legacyHttpParser) {
// https://github.com/nodejs/node/issues/43798
input.extraHttpOptions = { insecureHTTPParser: true }