T09 · Insecure Skill Coding Practices
- Location
upload.py:148- Finding
Dry-run mode can create a remote Pinecone index
- Content
View full analysis
Vulnerability Details
File Location:
upload.py:148-151,upload.py:174-207, andpinecone_tool.py:390-412
Vulnerability Type: Unexpected remote state modification caused by eager service initialization
Risk Level: MediumVulnerable Code
python # upload.py:148-151 # 初始化知识库 kb = KnowledgeBase(config) # 收集所有要处理的文件python # upload.py:174-207 # 预览模式 if args.dry_run: print("预览模式(不实际上传)\n") all_files = [] # 收集单个文件 for file_path in files_to_process: doc = kb.loader.load(file_path) if doc: all_files.append(doc) # 收集目录文件 for dir_path in directories_to_process: docs = kb.loader.load_directory(dir_path, args.recursive) all_files.extend(docs) print(f"找到 {len(all_files)} 个文件:\n") total_chunks = 0 for doc in all_files: chunks = kb.splitter.split(doc) total_chunks += len(chunks) print(f" {doc.filename}") print(f" 路径: {doc.source}") print(f" 类型: {doc.file_type}") print(f" 大小: {format_size(doc.metadata.get('size_bytes', 0))}") print(f" 预计块数: {len(chunks)}") print() print(f"\n预计总块数: {total_chunks}") print("\n预览完成,移除 --dry-run 参数执行实际上传") returnpython # pinecone_tool.py:390-412 class PineconeManager: """Pinecone 管理器 - 封装所有 Pinecone 操作""" MAX_BATCH_SIZE_MB = 2 # Pinecone 单批次限制 2MB def __init__(self, config: Config): self.config = config self.pc = Pinecone(api_key=config.PINECONE_API_KEY) self.index = self._get_or_create_index() def _get_or_create_index(self): """获取或创建索引""" index_name = self.config.INDEX_NAME # 检查索引是否存在 if index_name not in self.pc.list_indexes().names(): print(f"📝 创建索引: {index_name}") self.pc.create_index( name=ind ...[truncated 2268 chars]- Remediation
View remediation
Remediation Suggestions
- Evaluate
args.dry_runbefore constructing any object that initializes a remote service. - In dry-run mode, instantiate only
DocumentLoaderandTextSplitter, which are the components required for local preview processing. - Refactor
KnowledgeBaseto initializePineconeManagerlazily when an upload or search operation first requires it. - Separate index lookup from index creation. Index creation should require an explicit upload operation or a dedicated
--create-indexoption. - Add an automated test that runs dry-run with a mocked Pinecone client and asserts that
list_indexes,create_index,upsert, andqueryare never called. - Document that dry-run performs no embedding requests, Pinecone requests, resource creation, or vector uploads.
- Evaluate
