Skip to content

Commit

Permalink
[8.x] [Stack Connectors][SentinelOne + Crowdstrike] Fix the validatio…
Browse files Browse the repository at this point in the history
…n of external API responses that return non-JSON (ex. stream) (#203820) (#203920)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Stack Connectors][SentinelOne + Crowdstrike] Fix the validation of
external API responses that return non-JSON (ex. stream)
(#203820)](#203820)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paul
Tavares","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-11T19:48:57Z","message":"[Stack
Connectors][SentinelOne + Crowdstrike] Fix the validation of external
API responses that return non-JSON (ex. stream) (#203820)\n\n##
Summary\r\n\r\n- Changes the validation for API responses from
SentinelOne and\r\nCrowdstrike to allow anything\r\n- The prior fix
changed it to validate that the responses were `JSON`,\r\nbut the some
APIs can return non-JSON: example: a `stream` as is the\r\ncase for file
download.","sha":"520c7c6d58356770708a0567d8fac3c55d75f8cc","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:Defend
Workflows","backport:prev-major","v8.18.0","v8.16.2","v8.17.1"],"title":"[Stack
Connectors][SentinelOne + Crowdstrike] Fix the validation of external
API responses that return non-JSON (ex.
stream)","number":203820,"url":"https://github.com/elastic/kibana/pull/203820","mergeCommit":{"message":"[Stack
Connectors][SentinelOne + Crowdstrike] Fix the validation of external
API responses that return non-JSON (ex. stream) (#203820)\n\n##
Summary\r\n\r\n- Changes the validation for API responses from
SentinelOne and\r\nCrowdstrike to allow anything\r\n- The prior fix
changed it to validate that the responses were `JSON`,\r\nbut the some
APIs can return non-JSON: example: a `stream` as is the\r\ncase for file
download.","sha":"520c7c6d58356770708a0567d8fac3c55d75f8cc"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203820","number":203820,"mergeCommit":{"message":"[Stack
Connectors][SentinelOne + Crowdstrike] Fix the validation of external
API responses that return non-JSON (ex. stream) (#203820)\n\n##
Summary\r\n\r\n- Changes the validation for API responses from
SentinelOne and\r\nCrowdstrike to allow anything\r\n- The prior fix
changed it to validate that the responses were `JSON`,\r\nbut the some
APIs can return non-JSON: example: a `stream` as is the\r\ncase for file
download.","sha":"520c7c6d58356770708a0567d8fac3c55d75f8cc"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Paul Tavares <[email protected]>
  • Loading branch information
kibanamachine and paul-tavares authored Dec 16, 2024
1 parent 3e42292 commit 5194f26
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/stack_connectors/common/crowdstrike/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const CrowdstrikeSecretsSchema = schema.object({
clientSecret: schema.string(),
});

export const CrowdstrikeApiDoNotValidateResponsesSchema = schema.any();

export const RelaxedCrowdstrikeBaseApiResponseSchema = schema.maybe(
schema.object({}, { unknowns: 'allow' })
);
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/stack_connectors/common/sentinelone/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const SentinelOneSecretsSchema = schema.object({
token: schema.string(),
});

export const SentinelOneApiDoNotValidateResponsesSchema = schema.any();

export const SentinelOneBaseApiResponseSchema = schema.maybe(
schema.object({}, { unknowns: 'allow' })
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import type {
import {
CrowdstrikeHostActionsParamsSchema,
CrowdstrikeGetAgentsParamsSchema,
CrowdstrikeGetTokenResponseSchema,
CrowdstrikeHostActionsResponseSchema,
RelaxedCrowdstrikeBaseApiResponseSchema,
CrowdstrikeRTRCommandParamsSchema,
CrowdstrikeExecuteRTRResponseSchema,
CrowdstrikeGetScriptsParamsSchema,
CrowdStrikeExecuteRTRResponse,
CrowdstrikeApiDoNotValidateResponsesSchema,
CrowdstrikeGetTokenResponseSchema,
} from '../../../common/crowdstrike/schema';
import { SUB_ACTION } from '../../../common/crowdstrike/constants';
import { CrowdstrikeError } from './error';
Expand Down Expand Up @@ -229,7 +230,8 @@ export class CrowdstrikeConnector extends SubActionConnector<
'Content-Type': 'application/x-www-form-urlencoded',
authorization: 'Basic ' + CrowdstrikeConnector.base64encodedToken,
},
responseSchema: CrowdstrikeGetTokenResponseSchema,
responseSchema:
CrowdstrikeApiDoNotValidateResponsesSchema as unknown as typeof CrowdstrikeGetTokenResponseSchema,
},
connectorUsageCollector
);
Expand Down Expand Up @@ -265,7 +267,7 @@ export class CrowdstrikeConnector extends SubActionConnector<
// where the external system might add/remove/change values in the response that we have no
// control over.
responseSchema:
RelaxedCrowdstrikeBaseApiResponseSchema as unknown as SubActionRequestParams<R>['responseSchema'],
CrowdstrikeApiDoNotValidateResponsesSchema as unknown as SubActionRequestParams<R>['responseSchema'],
headers: {
...req.headers,
Authorization: `Bearer ${CrowdstrikeConnector.token}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
SentinelOneGetRemoteScriptResultsParamsSchema,
SentinelOneDownloadRemoteScriptResultsParamsSchema,
SentinelOneDownloadRemoteScriptResultsResponseSchema,
SentinelOneBaseApiResponseSchema,
SentinelOneApiDoNotValidateResponsesSchema,
} from '../../../common/sentinelone/schema';
import { SUB_ACTION } from '../../../common/sentinelone/constants';
import {
Expand Down Expand Up @@ -405,7 +405,7 @@ export class SentinelOneConnector extends SubActionConnector<
// where the external system might add/remove/change values in the response that we have no
// control over.
responseSchema:
SentinelOneBaseApiResponseSchema as unknown as SubActionRequestParams<R>['responseSchema'],
SentinelOneApiDoNotValidateResponsesSchema as unknown as SubActionRequestParams<R>['responseSchema'],
params: {
...req.params,
APIToken: this.secrets.token,
Expand Down

0 comments on commit 5194f26

Please sign in to comment.