-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[backend/pycti] Prevent file upload looping (#14585) #14749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
236d0da
970ddc9
9072ce1
7a0d3d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,7 @@ import { PLAYBOOK_DATA_STREAM_PIR } from './components/data-stream-pir-component | |
| import { convertStoreToStix_2_1 } from '../../database/stix-2-1-converter'; | ||
| import { ENTITY_TYPE_SECURITY_COVERAGE, INPUT_COVERED, type StixSecurityCoverage, type StoreEntitySecurityCoverage } from '../securityCoverage/securityCoverage-types'; | ||
| import { pushAll } from '../../utils/arrayUtil'; | ||
| import { getFileContent } from '../../database/raw-file-storage'; | ||
|
|
||
| // region built in playbook components | ||
| interface LoggerConfiguration { | ||
|
|
@@ -625,8 +626,26 @@ export const PLAYBOOK_CONTAINER_WRAPPER_COMPONENT: PlaybookComponent<ContainerWr | |
| (<StixCaseIncident>container).extensions[STIX_EXT_OCTI].granted_refs = (<StixIncident>baseData).extensions[STIX_EXT_OCTI].granted_refs; | ||
| } | ||
| // Copy files from the main element to the container if requested | ||
| if (copyFiles && baseData.extensions[STIX_EXT_OCTI].files && baseData.extensions[STIX_EXT_OCTI].files.length > 0) { | ||
| container.extensions[STIX_EXT_OCTI].files = baseData.extensions[STIX_EXT_OCTI].files; | ||
| const stixFileExtensions = baseData.extensions[STIX_EXT_OCTI].files; | ||
| if (copyFiles && stixFileExtensions && stixFileExtensions.length > 0) { | ||
| // We need to get the files and add the data inside | ||
| const copiedFiles = []; | ||
| for (let index = 0; index < stixFileExtensions.length; index += 1) { | ||
| const currentFile = stixFileExtensions[index]; | ||
| try { | ||
| const currentFileUri = currentFile.uri; | ||
| const fileId = currentFileUri.replace('/storage/get/', ''); | ||
| const currentFileContent = await getFileContent(fileId, 'base64'); | ||
| if (currentFileContent) { | ||
| copiedFiles.push({ ...currentFile, data: currentFileContent }); | ||
| } else { | ||
| logApp.error("Can't copy file from main element to the container: empty content", { name: currentFile.name }); | ||
| } | ||
| } catch (e) { | ||
| logApp.error("Can't copy file from main element to the container", { cause: e, name: currentFile.name }); | ||
| } | ||
| } | ||
| container.extensions[STIX_EXT_OCTI].files = copiedFiles; | ||
|
Comment on lines
+629
to
+648
|
||
| } | ||
| if (STIX_DOMAIN_OBJECT_CONTAINER_CASES.includes(container_type) && caseTemplates.length > 0) { | ||
| const tasks = await createTaskFromCaseTemplates(caseTemplates, (container as StixContainer)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes
currentFile.uriis always a/storage/get/<id>path. In STIX 2.1 conversion, files that already includedataoften haveuri: 'unknown'; in that case this code will try to fetchgetFileContent('unknown', ...)and log errors. Consider short-circuiting whencurrentFile.datais already present (or whenuriis missing/unknown) and just reuse the existingdata.