Disable allowAbsoluteUrls for axios (#215138)

## Summary
After https://github.com/elastic/kibana/pull/214843, `axios` client
usages need to set a flag to prevent the vulnerable behavior.

To reviewers: if you think it's a mistake, and you created a client to
request for absolute URLs, consider unsetting the `baseURL` to
communicate intent.
This commit is contained in:
Alex Szabo 2025-03-25 09:52:36 +01:00 committed by GitHub
parent bf5af0d011
commit e40b17aa22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 15 additions and 0 deletions

View file

@ -54,6 +54,7 @@ export class ApmClient {
auth,
baseURL,
timeout,
allowAbsoluteUrls: false,
});
this.logger = logger || console;

View file

@ -102,6 +102,7 @@ it('captures a list of failed test issue, loads the bodies for each issue, and o
"calls": Array [
Array [
Object {
"allowAbsoluteUrls": false,
"baseURL": "https://ci-stats.kibana.dev",
"data": Object {
"failures": Array [
@ -117,6 +118,7 @@ it('captures a list of failed test issue, loads the bodies for each issue, and o
],
Array [
Object {
"allowAbsoluteUrls": false,
"baseURL": "https://ci-stats.kibana.dev",
"data": Object {
"failures": Array [

View file

@ -119,6 +119,7 @@ export class ExistingFailedTestIssues {
const resp = await Axios.request<FindFailedTestIssuesResponse>({
method: 'POST',
baseURL: BASE_URL,
allowAbsoluteUrls: false,
url: '/v1/find_failed_test_issues',
data: {
failures: failures.map((f) => ({

View file

@ -29,6 +29,7 @@ export class GithubApi {
constructor(private accessToken?: string) {
this.api = axios.create({
baseURL: 'https://api.github.com/',
allowAbsoluteUrls: false,
headers: {
Accept: 'application/vnd.github.v3+json',
'User-Agent': 'kibana/update_prs_cli',

View file

@ -372,6 +372,7 @@ export class CiStatsReporter {
method: 'POST',
url: path,
baseURL: BASE_URL,
allowAbsoluteUrls: false,
headers,
data: body,
params: query,

View file

@ -405,6 +405,7 @@ describe('request', () => {
defaults: {
...axios.defaults,
baseURL: 'https://here-we-go.com',
allowAbsoluteUrls: false,
},
} as unknown as AxiosInstance,
url: '/test',

View file

@ -23,6 +23,7 @@ export async function callKibana<T>({
const { data } = await axios.request({
...options,
baseURL: baseUrl,
allowAbsoluteUrls: false,
auth: { username, password },
headers: { 'kbn-xsrf': 'true', 'x-elastic-internal-origin': 'kibana', ...options.headers },
});

View file

@ -53,6 +53,7 @@ export async function initDiagnosticsBundle({
const kibanaClientOpts = {
baseURL: kbHost ?? parsedCloudId.kibanaHost,
allowAbsoluteUrls: false,
auth,
headers: {
'kbn-xsrf': 'true',

View file

@ -27,6 +27,7 @@ export async function callKibana<T>({
const { data } = await axios.request({
...options,
baseURL: baseUrl,
allowAbsoluteUrls: false,
auth: { username, password },
headers: { ...DEFAULT_HEADERS, ...options.headers },
});

View file

@ -23,6 +23,7 @@ export async function callKibana<T>({
const { data } = await axios.request({
...options,
baseURL: baseUrl,
allowAbsoluteUrls: false,
auth: { username, password },
headers: { 'kbn-xsrf': 'true', 'x-elastic-internal-origin': 'kibana', ...options.headers },
});

View file

@ -48,6 +48,7 @@ export function SpacesServiceProvider({ getService }: FtrProviderContext) {
'kbn-xsrf': 'x-pack/ftr/services/spaces/space',
},
baseURL: url,
allowAbsoluteUrls: false,
maxRedirects: 0,
validateStatus: () => true, // we do our own validation below and throw better error messages
httpsAgent,

View file

@ -23,6 +23,7 @@ export async function callKibana<T>({
const { data } = await axios.request({
...options,
baseURL: baseUrl,
allowAbsoluteUrls: false,
auth: { username, password },
headers: { 'kbn-xsrf': 'true', ...options.headers },
});

View file

@ -19,6 +19,7 @@ export class FeaturesService {
this.axios = axios.create({
headers: { 'kbn-xsrf': 'x-pack/ftr/services/features' },
baseURL: url,
allowAbsoluteUrls: false,
maxRedirects: 0,
validateStatus: () => true, // we'll handle our own statusCodes and throw informative errors
});

View file

@ -39,6 +39,7 @@ export class UICapabilitiesService {
this.axios = axios.create({
headers: { 'kbn-xsrf': 'x-pack/ftr/services/ui_capabilities' },
baseURL: url,
allowAbsoluteUrls: false,
maxRedirects: 0,
validateStatus: () => true, // we'll handle our own statusCodes and throw informative errors
});