{"record":{"id":"140e46ee7731097e","repo":"Tencent/WeKnora","slug":"invalid-source-path-w","errorCode":null,"errorMessage":"invalid source path: %w","messagePattern":"invalid source path: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/ks3.go","lineNumber":196,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to upload bytes to KS3: %w\", err)\n\t}\n\n\treturn fmt.Sprintf(\"%s%s/%s\", ks3Scheme, s.bucketName, objectKey), nil\n}\n\n// CopyFile copies an existing KS3 object to a new knowledge-owned object using a\n// server-side CopyObject (no data leaves KS3). The destination uses the same\n// layout as SaveFile. Returns ErrCrossBackendCopy when srcPath is not a ks3:// path.\nfunc (s *ks3FileService) CopyFile(ctx context.Context,\n\tsrcPath string, tenantID uint64, knowledgeID string,\n) (string, error) {\n\tsrcBucket, srcKey, err := parseKS3FilePath(srcPath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"ks3 copy rejected source %q: %w\", srcPath, ErrCrossBackendCopy)\n\t}\n\tif err := utils.SafeObjectKey(srcKey); err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid source path: %w\", err)\n\t}\n\n\text := filepath.Ext(srcPath)\n\tdestKey := joinKS3Key(s.pathPrefix, fmt.Sprintf(\"%d\", tenantID), knowledgeID, uuid.New().String()+ext)\n\n\t_, err = s.client.CopyObject(&ks3s3.CopyObjectInput{\n\t\tBucket:       ks3aws.String(s.bucketName),\n\t\tKey:          ks3aws.String(destKey),\n\t\tSourceBucket: ks3aws.String(srcBucket),\n\t\tSourceKey:    ks3aws.String(srcKey),\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to copy file in KS3: %w\", err)\n\t}\n\n\tnewPath := fmt.Sprintf(\"%s%s/%s\", ks3Scheme, s.bucketName, destKey)\n\tlogger.Infof(ctx, \"Copied KS3 object %s to %s\", srcPath, newPath)\n\treturn newPath, nil","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/ks3.go#L178-L214","documentation":"KS3 copy guard: the source object key was rejected by SafeObjectKey, meaning the key extracted from the ks3:// path is unsafe (path traversal, absolute segments, or invalid characters), so the server-side copy is refused before any KS3 request.","triggerScenarios":"Thrown at internal/application/service/file/ks3.go:196 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Sanitize the source object key before calling CopyFile","Reject user-supplied keys with traversal patterns at ingestion","Log the offending key to trace the malformed input"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}