Skip to content

Commit 4a642f0

Browse files
authored
Chore/Remove Deprecated File Path Unstructured (FlowiseAI#5478)
* Refactor UnstructuredFile and UnstructuredFolder loaders to remove deprecated file path handling and enhance folder path validation. Ensure folder paths are sanitized and validated against path traversal attacks. * Update UnstructuredFolder.ts
1 parent ceb0512 commit 4a642f0

File tree

1 file changed

+2
-47
lines changed

1 file changed

+2
-47
lines changed

packages/components/nodes/documentloaders/Unstructured/UnstructuredFile.ts

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import {
44
UnstructuredLoaderOptions,
55
UnstructuredLoaderStrategy,
66
SkipInferTableTypes,
7-
HiResModelName,
8-
UnstructuredLoader as LCUnstructuredLoader
7+
HiResModelName
98
} from '@langchain/community/document_loaders/fs/unstructured'
109
import { getCredentialData, getCredentialParam, handleEscapeCharacters } from '../../../src/utils'
1110
import { getFileFromStorage, INodeOutputsValue } from '../../../src'
1211
import { UnstructuredLoader } from './Unstructured'
13-
import { isPathTraversal, isUnsafeFilePath } from '../../../src/validator'
14-
import sanitize from 'sanitize-filename'
15-
import path from 'path'
1612

1713
class UnstructuredFile_DocumentLoaders implements INode {
1814
label: string
@@ -44,17 +40,6 @@ class UnstructuredFile_DocumentLoaders implements INode {
4440
optional: true
4541
}
4642
this.inputs = [
47-
/** Deprecated
48-
{
49-
label: 'File Path',
50-
name: 'filePath',
51-
type: 'string',
52-
placeholder: '',
53-
optional: true,
54-
warning:
55-
'Use the File Upload instead of File path. If file is uploaded, this path is ignored. Path will be deprecated in future releases.'
56-
},
57-
*/
5843
{
5944
label: 'Files Upload',
6045
name: 'fileObject',
@@ -455,7 +440,6 @@ class UnstructuredFile_DocumentLoaders implements INode {
455440
}
456441

457442
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
458-
const filePath = nodeData.inputs?.filePath as string
459443
const unstructuredAPIUrl = nodeData.inputs?.unstructuredAPIUrl as string
460444
const strategy = nodeData.inputs?.strategy as UnstructuredLoaderStrategy
461445
const encoding = nodeData.inputs?.encoding as string
@@ -560,37 +544,8 @@ class UnstructuredFile_DocumentLoaders implements INode {
560544
docs.push(...loaderDocs)
561545
}
562546
}
563-
} else if (filePath) {
564-
if (!filePath || typeof filePath !== 'string') {
565-
throw new Error('Invalid file path format')
566-
}
567-
568-
if (isPathTraversal(filePath) || isUnsafeFilePath(filePath)) {
569-
throw new Error('Invalid path characters detected in filePath - path traversal not allowed')
570-
}
571-
572-
const parsedPath = path.parse(filePath)
573-
const sanitizedFilename = sanitize(parsedPath.base)
574-
575-
if (!sanitizedFilename || sanitizedFilename.trim() === '') {
576-
throw new Error('Invalid filename after sanitization')
577-
}
578-
579-
const sanitizedFilePath = path.join(parsedPath.dir, sanitizedFilename)
580-
581-
if (!path.isAbsolute(sanitizedFilePath)) {
582-
throw new Error('File path must be absolute')
583-
}
584-
585-
if (sanitizedFilePath.includes('..')) {
586-
throw new Error('Invalid file path - directory traversal not allowed')
587-
}
588-
589-
const loader = new LCUnstructuredLoader(sanitizedFilePath, obj)
590-
const loaderDocs = await loader.load()
591-
docs.push(...loaderDocs)
592547
} else {
593-
throw new Error('File path or File upload is required')
548+
throw new Error('File upload is required')
594549
}
595550

596551
if (metadata) {

0 commit comments

Comments
 (0)