Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: harden credential and input handling (#21593)

buua436738a23965060
diff --git a/deps/download_deps.py b/deps/download_deps.py
index 62df360fff..d7b8647d5f 100755
--- a/deps/download_deps.py
+++ b/deps/download_deps.py
@@ -69,11 +69,17 @@ REPO_ROOT = os.path.dirname(SCRIPT_DIR)
# recording the downloaded hash so the next run detects changes. Both first and
# later runs therefore run the download directly without manual setup.
NOTO_CJK_FONT_SHA256 = ""
+GH_PROXY_URL = "https://gh-proxy.com/"
def gh_proxy() -> str:
- """GitHub release proxy prefix (gh-proxy.com behind the GFW), else empty."""
- return os.environ.get("GH_PROXY") or ""
+ """Return the supported GitHub proxy prefix, rejecting arbitrary hosts."""
+ proxy = (os.environ.get("GH_PROXY") or "").strip()
+ if not proxy:
+ return ""
+ if proxy.rstrip("/") != GH_PROXY_URL.rstrip("/"):
+ raise RuntimeError(f"GH_PROXY must be empty or {GH_PROXY_URL!r}")
+ return GH_PROXY_URL
def cl100k_url() -> str:
diff --git a/example/http/chat_assistant_example.sh b/example/http/chat_assistant_example.sh
index bcac93fadd..511bd0626c 100644
--- a/example/http/chat_assistant_example.sh
+++ b/example/http/chat_assistant_example.sh
@@ -17,7 +17,7 @@
# Variables
HOST_ADDRESS="${RAGFLOW_HOST_ADDRESS:-http://localhost:9380}"
-API_KEY="${RAGFLOW_API_KEY:-ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm}"
+API_KEY="${RAGFLOW_API_KEY:?Set RAGFLOW_API_KEY before running this example}"
# Check for jq
if ! command -v jq &> /dev/null; then
diff --git a/example/http/chunk_example.sh b/example/http/chunk_example.sh
index f84787b8e8..bb37a70e63 100644
--- a/example/http/chunk_example.sh
+++ b/example/http/chunk_example.sh
@@ -17,7 +17,7 @@
# Variables
HOST_ADDRESS="${RAGFLOW_HOST_ADDRESS:-http://localhost:9380}"
-API_KEY="${RAGFLOW_API_KEY:-ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm}"
+API_KEY="${RAGFLOW_API_KEY:?Set RAGFLOW_API_KEY before running this example}"
# Check for jq
if ! command -v jq &> /dev/null; then
diff --git a/example/http/dataset_example.sh b/example/http/dataset_example.sh
index 1d2e8fa68f..d0639a1156 100644
--- a/example/http/dataset_example.sh
+++ b/example/http/dataset_example.sh
@@ -14,12 +14,14 @@
# limitations under the License.
#
+API_KEY="${RAGFLOW_API_KEY:?Set RAGFLOW_API_KEY before running this example}"
+
# Create a dataset
echo -e "\n-- Create a dataset"
curl --request POST \
--url http://localhost:9380/api/v1/datasets \
--header 'Content-Type: application/json' \
- --header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm' \
+ --header "Authorization: Bearer ${API_KEY}" \
--data '{
"name": "test"
}'
@@ -29,7 +31,7 @@ echo -e "\n-- Update the dataset"
curl --request PUT \
--url http://localhost:9380/api/v1/datasets/2e898768a0bc11efb46a0242ac120006 \
--header 'Content-Type: application/json' \
- --header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm' \
+ --header "Authorization: Bearer ${API_KEY}" \
--data '
{
"name": "updated_dataset"
@@ -39,20 +41,20 @@ curl --request PUT \
echo -e "\n-- List datasets"
curl --request GET \
--url http://127.0.0.1:9380/api/v1/datasets \
- --header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm'
+ --header "Authorization: Bearer ${API_KEY}"
# List datasets with parsing status
echo -e "\n-- List datasets with parsing status"
curl --request GET \
--url 'http://127.0.0.1:9380/api/v1/datasets?include_parsing_status=true' \
- --header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm'
+ --header "Authorization: Bearer ${API_KEY}"
# Delete datasets
echo -e "\n-- Delete datasets"
curl --request DELETE \
--url http://localhost:9380/api/v1/datasets \
--header 'Content-Type: application/json' \
- --header 'Authorization: Bearer ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm' \
+ --header "Authorization: Bearer ${API_KEY}" \
--data '{
"ids": ["301298b8a0bc11efa0440242ac120006"]
}'
diff --git a/example/http/document_example.sh b/example/http/document_example.sh
index c714281e69..05f52a1c8b 100644
--- a/example/http/document_example.sh
+++ b/example/http/document_example.sh
@@ -2,7 +2,7 @@
set -euo pipefail
HOST_ADDRESS="${RAGFLOW_HOST_ADDRESS:-http://localhost:9380}"
-API_KEY="${RAGFLOW_API_KEY:-ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm}"
+API_KEY="${RAGFLOW_API_KEY:?Set RAGFLOW_API_KEY before running this example}"
command -v jq >/dev/null || { echo "jq is required" >&2; exit 1; }
TEMP_FILE=$(mktemp)
diff --git a/example/http/retrieval_example.sh b/example/http/retrieval_example.sh
index e8ad435dd8..781f0efe29 100644
--- a/example/http/retrieval_example.sh
+++ b/example/http/retrieval_example.sh
@@ -17,7 +17,7 @@
# Variables
HOST_ADDRESS="${RAGFLOW_HOST_ADDRESS:-http://localhost:9380}"
-API_KEY="${RAGFLOW_API_KEY:-ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm}"
+API_KEY="${RAGFLOW_API_KEY:?Set RAGFLOW_API_KEY before running this example}"
# Check for jq
if ! command -v jq &> /dev/null; then
diff --git a/example/sdk/chat_assistant_example.py b/example/sdk/chat_assistant_example.py
deleted file mode 100644
index b282f7fe91..0000000000
--- a/example/sdk/chat_assistant_example.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-"""
-The example demonstrates how to create a chat assistant, manage sessions,
-and perform both standard and streaming chat.
-"""
-
-from ragflow_sdk import RAGFlow
-import sys
-import os
-
-HOST_ADDRESS = os.environ.get("RAGFLOW_HOST_ADDRESS", "http://127.0.0.1")
-API_KEY = os.environ.get("RAGFLOW_API_KEY", "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm")
-
-try:
- rag = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
-
- # 1. Create a dataset to be used by the assistant
- print("Creating dataset...")
- dataset = rag.create_dataset(name="assistant_example_dataset")
-
- # 2. Create a chat assistant
- print("Creating chat assistant...")
- assistant = rag.create_chat(
- name="Test Assistant",
- dataset_ids=[dataset.id],
- llm_id="deepseek-chat", # Example LLM ID, replace with your actual model ID
- prompt_config={"system": "You are a helpful assistant."},
- )
- print(f"Assistant created: {assistant.name} (ID: {assistant.id})")
-
- # 3. Create a session
- print("Creating a new session...")
- session = assistant.create_session(name="Example Session")
- print(f"Session created: {session.name} (ID: {session.id})")
-
- # 4. Standard chat (non-streaming)
- print("\n--- Standard Chat ---")
- question = "What is RAGFlow?"
- print(f"User: {question}")
-
- # ask returns a generator of Message objects
- # for stream=False, it yields once with the full answer
- for message in session.ask(question=question, stream=False):
- print(f"Assistant: {message.content}")
- if hasattr(message, "reference") and message.reference:
- print(f"References used: {len(message.reference)} chunks")
-
- # 5. Streaming chat
- print("\n--- Streaming Chat ---")
- question = "Tell me more about its features."
- print(f"User: {question}")
- print("Assistant: ", end="", flush=True)
-
- for message in session.ask(question=question, stream=True):
- # In streaming mode, each message.content usually contains the incremental part
- # or the full content so far depending on the SDK implementation.
- # Based on RAGFlow SDK, it typically yields incremental parts.
- print(message.content, end="", flush=True)
- print("\n")
-
- # 6. List sessions
- print("Listing sessions for this assistant...")
- sessions = assistant.list_sessions(page=1, page_size=10)
- for s in sessions:
- print(f"- {s.name} (ID: {s.id})")
-
- # Cleanup
- print("\nCleaning up...")
- assistant.delete_sessions(ids=[session.id])
- rag.delete_chats(ids=[assistant.id])
- rag.delete_datasets(ids=[dataset.id])
-
- print("Chat assistant example done.")
- sys.exit(0)
-
-except Exception as e:
- print(f"An error occurred: {e}")
- sys.exit(-1)
diff --git a/example/sdk/chunk_example.py b/example/sdk/chunk_example.py
deleted file mode 100644
index 71acb5bee3..0000000000
--- a/example/sdk/chunk_example.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-"""
-The example demonstrates chunk management (Add, List, Update, Delete, Retrieve)
-within a RAGFlow dataset using the Python SDK.
-"""
-
-from ragflow_sdk import RAGFlow
-import sys
-import time
-import os
-
-HOST_ADDRESS = os.environ.get("RAGFLOW_HOST_ADDRESS", "http://127.0.0.1")
-API_KEY = os.environ.get("RAGFLOW_API_KEY", "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm")
-
-try:
- rag = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
-
- # 1. Create a dataset
- print("Creating dataset...")
- dataset = rag.create_dataset(name="chunk_example_dataset")
-
- # 2. Upload a document
- print("Uploading document...")
- # Using a simple text content for example
- content = "RAGFlow is an open-source RAG (Retrieval-Augmented Generation) engine based on deep document understanding."
- docs = dataset.upload_documents([{"display_name": "sample.txt", "blob": content.encode("utf-8")}])
- doc = docs[0]
-
- # 3. Parse the document (required before manual chunk operations if you want it to be processed)
- print("Parsing document...")
- dataset.async_parse_documents([doc.id])
-
- # Wait for parsing to complete with timeout
- MAX_WAIT = 120 # seconds
- elapsed = 0
- while elapsed < MAX_WAIT:
- doc_status = dataset.list_documents(id=doc.id)[0]
- if doc_status.run == "DONE" and doc_status.progress >= 1.0:
- print(f"Parsing completed for {doc.id} after {elapsed}s.")
- break
- print(f"Parsing progress: {doc_status.progress:.2f}")
- time.sleep(2)
- elapsed += 2
- else:
- print("Parsing timed out.")
- sys.exit(-1)
-
- # 4. Add a manual chunk
- print("Adding a manual chunk...")
- chunk = doc.add_chunk(content="RAGFlow features a streamlined RAG workflow.")
- print(f"Added chunk ID: {chunk.id}")
-
- # 5. List chunks
- print("Listing chunks...")
- chunks = doc.list_chunks(page=1, page_size=10)
- print(f"Total chunks found: {len(chunks)}")
- for i, c in enumerate(chunks):
- print(f"Chunk {i}: {c.content[:50]}...")
-
- # 6. Update a chunk
- print("Updating chunk...")
- chunk.update({"content": "RAGFlow features a streamlined and powerful RAG workflow."})
-
- # 7. Delete the chunk
- print("Deleting chunk...")
- doc.delete_chunks([chunk.id])
-
- # Cleanup
- print("Cleaning up dataset...")
- rag.delete_datasets(ids=[dataset.id])
-
- print("Chunk example done.")
- sys.exit(0)
-
-except Exception as e:
- print(f"An error occurred: {e}")
- sys.exit(-1)
diff --git a/example/sdk/dataset_example.py b/example/sdk/dataset_example.py
deleted file mode 100644
index c15e959f06..0000000000
--- a/example/sdk/dataset_example.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-"""
-The example is about CRUD operations (Create, Read, Update, Delete) on a dataset.
-"""
-
-from ragflow_sdk import RAGFlow
-import sys
-
-HOST_ADDRESS = "http://127.0.0.1"
-API_KEY = "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm"
-
-try:
- # create a ragflow instance
- ragflow_instance = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
-
- # crate a dataset instance
- dataset_instance = ragflow_instance.create_dataset(name="dataset_instance")
-
- # update the dataset instance
- updated_message = {"name": "updated_dataset"}
- updated_dataset = dataset_instance.update(updated_message)
-
- # get the dataset (list datasets)
- print(dataset_instance)
- print(updated_dataset)
-
- # delete the dataset (delete datasets)
- to_be_deleted_datasets = [dataset_instance.id]
- ragflow_instance.delete_datasets(ids=to_be_deleted_datasets)
-
- print("test done")
- sys.exit(0)
-
-except Exception as e:
- print(str(e))
- sys.exit(-1)
diff --git a/example/sdk/document_example.py b/example/sdk/document_example.py
deleted file mode 100644
index 9fcef53597..0000000000
--- a/example/sdk/document_example.py
+++ /dev/null
@@ -1,34 +0,0 @@
-"""Manage a document through its dataset lifecycle with the Python SDK."""
-
-import os
-
-from ragflow_sdk import RAGFlow
-
-HOST_ADDRESS = os.environ.get("RAGFLOW_HOST_ADDRESS", "http://127.0.0.1:9380")
-API_KEY = os.environ.get("RAGFLOW_API_KEY", "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm")
-
-
-rag = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
-dataset = rag.create_dataset(name="document_example_dataset")
-document = None
-try:
- documents = dataset.upload_documents([{"display_name": "sample.txt", "blob": b"RAGFlow is an open-source RAG engine.\n"}])
- document = documents[0]
- print(f"Uploaded {document.name} (id={document.id})")
-
- listed = dataset.list_documents(id=document.id)
- document = listed[0]
- print(f"Listed {document.name} (run={document.run})")
-
- document.update({"name": "renamed_sample.txt"})
- print(f"Renamed document to {document.name}")
-
- statuses = dataset.parse_documents([document.id])
- status = next(item for item in statuses if item[0] == document.id)
- if str(status[1]).upper() != "DONE":
- raise RuntimeError(f"Parsing failed: {status[1]}")
- print(f"Parsing completed: {status[2]} chunks, {status[3]} tokens")
-finally:
- if document is not None:
- dataset.delete_documents(ids=[document.id])
- rag.delete_datasets(ids=[dataset.id])
diff --git a/example/sdk/retrieval_example.py b/example/sdk/retrieval_example.py
deleted file mode 100644
index cb6de4a6e0..0000000000
--- a/example/sdk/retrieval_example.py
+++ /dev/null
@@ -1,95 +0,0 @@
-#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-"""
-The example demonstrates the RAG retrieval flow using the Python SDK.
-It shows how to perform semantic search across one or more datasets.
-"""
-
-from ragflow_sdk import RAGFlow
-import sys
-import time
-import os
-
-HOST_ADDRESS = os.environ.get("RAGFLOW_HOST_ADDRESS", "http://127.0.0.1")
-API_KEY = os.environ.get("RAGFLOW_API_KEY", "ragflow-IzZmY1MGVhYTBhMjExZWZiYTdjMDI0Mm")
-
-try:
- rag = RAGFlow(api_key=API_KEY, base_url=HOST_ADDRESS)
-
- # 1. Create a dataset
- print("Creating dataset...")
- dataset = rag.create_dataset(name="retrieval_example_dataset")
-
- # 2. Upload and parse a document to have content for retrieval
- print("Uploading and parsing document...")
- content = "RAGFlow is an open-source RAG engine based on deep document understanding. It features a streamlined RAG workflow for businesses of any size."
- docs = dataset.upload_documents([{"display_name": "ragflow_info.txt", "blob": content.encode("utf-8")}])
- doc = docs[0]
-
- # Wait for parsing to complete with timeout
- print("Parsing document...")
- dataset.async_parse_documents([doc.id])
- MAX_WAIT = 120 # seconds
- elapsed = 0
- while elapsed < MAX_WAIT:
- doc_status = dataset.list_documents(id=doc.id)[0]
- if doc_status.run == "DONE" and doc_status.progress >= 1.0:
- break
- print(f"Parsing progress: {doc_status.progress:.2f}")
- time.sleep(2)
- elapsed += 2
- else:
- print("Parsing timed out.")
- sys.exit(-1)
- print(f"Document {doc.id} parsed after {elapsed}s and ready for retrieval.")
-
- # 3. Perform retrieval (Semantic Search)
- print("\n--- Performing Retrieval ---")
- question = "What is RAGFlow?"
- print(f"Question: {question}")
-
- # Retrieve relevant chunks from one or more datasets
- chunks = rag.retrieve(dataset_ids=[dataset.id], question=question, top_k=5, similarity_threshold=0.1)
-
- print(f"Found {len(chunks)} relevant chunks:")
- for i, chunk in enumerate(chunks):
- print(f"\nChunk {i + 1}:")
- print(f"Content: {chunk.content[:200]}...")
- print(f"Similarity Score: {chunk.similarity:.4f}")
- print(f"Source Document: {chunk.document_name}")
-
- # 4. Perform retrieval with additional parameters
- print("\n--- Performing Retrieval with Keyword Search ---")
- chunks = rag.retrieve(
- dataset_ids=[dataset.id],
- question="workflow for businesses",
- top_k=3,
- keyword=True, # Enable keyword search in addition to semantic search
- )
- for i, chunk in enumerate(chunks):
- print(f"Chunk {i + 1}: {chunk.content[:100]}... (Score: {chunk.similarity:.4f})")
-
- # Cleanup
- print("\nCleaning up...")
- rag.delete_datasets(ids=[dataset.id])
-
- print("Retrieval example done.")
- sys.exit(0)
-
-except Exception as e:
- print(f"An error occurred: {e}")
- sys.exit(-1)
diff --git a/internal/handler/chat_session_test.go b/internal/handler/chat_session_test.go
index c749c37a6d..94e7dd7995 100644
--- a/internal/handler/chat_session_test.go
+++ b/internal/handler/chat_session_test.go
@@ -119,3 +119,26 @@ func TestChatSessionHandlerChatCompletionsRejectsNonPositiveMaxTokens(t *testing
t.Fatalf("message=%v", got)
}
}
+
+func TestChatSessionHandlerChatCompletionsRejectsNonStringUserContent(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+ recorder := httptest.NewRecorder()
+ ctx, _ := gin.CreateTestContext(recorder)
+ ctx.Request = httptest.NewRequest(http.MethodPost, "/api/v1/chat/completions", strings.NewReader(`{"stream":false,"store_history_messages":false,"messages":[{"role":"user","content":{"type":"text","text":"probe"}}]}`))
+ ctx.Request.Header.Set("Content-Type", "application/json")
+ ctx.Set("user", &entity.User{ID: "user-1"})
+
+ handler := NewChatSessionHandler(service.NewChatSessionService(), nil)
+ handler.ChatCompletions(ctx)
+
+ var body map[string]interface{}
+ if err := json.Unmarshal(recorder.Body.Bytes(), &body); err != nil {
+ t.Fatalf("decode response body: %v", err)
+ }
+ if got := body["code"]; got != float64(common.CodeArgumentError) {
+ t.Fatalf("code=%v, want %d", got, common.CodeArgumentError)
+ }
+ if got, _ := body["message"].(string); got != "messages[].content must be a string or an array of content parts." {
+ t.Fatalf("message=%q, want non-string content validation error", got)
+ }
+}
diff --git a/internal/service/chat_pipeline.go b/internal/service/chat_pipeline.go
index 3dc1a37f17..a03ae585fc 100644
--- a/internal/service/chat_pipeline.go
+++ b/internal/service/chat_pipeline.go
@@ -236,13 +236,13 @@ func (s *ChatPipelineService) AsyncChat(
if len(messages) == 0 {
return nil, fmt.Errorf("AsyncChat: messages is empty")
}
+ if err := validateUserMessageContent(messages); err != nil {
+ return nil, common.NewCodedError(common.CodeArgumentError, err.Error())
+ }
lastMsg := messages[len(messages)-1]
if role, _ := lastMsg["role"].(string); role != "user" {
return nil, fmt.Errorf("the last content of this conversation is not from user")
}
- if _, err := NormalizeOpenAIMessageContent(lastMsg["content"]); err != nil {
- return nil, common.NewCodedError(common.CodeArgumentError, err.Error())
- }
if err := validateChatDatasetAccess(ctx, userID, chat.KBIDs); err != nil {
return nil, err
}
@@ -1380,6 +1380,23 @@ func (s *ChatPipelineService) AsyncChat(
return out, nil
}
+func validateUserMessageContent(messages []map[string]interface{}) error {
+ for i, message := range messages {
+ role, _ := message["role"].(string)
+ if role != "user" {
+ continue
+ }
+ content, ok := message["content"]
+ if !ok || content == nil {
+ return fmt.Errorf("messages[%d].content is required for user messages", i)
+ }
+ if _, err := NormalizeOpenAIMessageContent(content); err != nil {
+ return fmt.Errorf("messages[%d].content is invalid: %w", i, err)
+ }
+ }
+ return nil
+}
+
// deepResearchProgressCallback builds the progress callback handed to
// DeepResearcher.Research. Progress deltas are non-essential: once the
// consumer is gone (ctx canceled) they are dropped instead of blocking, so
diff --git a/internal/service/chat_pipeline_test.go b/internal/service/chat_pipeline_test.go
index 24ff237659..0b6c5685de 100644
--- a/internal/service/chat_pipeline_test.go
+++ b/internal/service/chat_pipeline_test.go
@@ -106,6 +106,34 @@ func TestAsyncChat_EmptyMessages(t *testing.T) {
}
}
+func TestAsyncChatRejectsNonStringUserContent(t *testing.T) {
+ s := &ChatPipelineService{}
+ messages := []map[string]interface{}{{"role": "user", "content": map[string]interface{}{"text": "question"}}}
+ _, err := s.AsyncChat(t.Context(), "user-1", dialForTest(""), messages, false, nil)
+ if err == nil || !strings.Contains(err.Error(), "messages[0].content is invalid") {
+ t.Fatalf("AsyncChat error = %v, want indexed invalid user content error", err)
+ }
+}
+
+func TestValidateUserMessageContentPreservesTextParts(t *testing.T) {
+ messages := []map[string]interface{}{{
+ "role": "user",
+ "content": []interface{}{
+ map[string]interface{}{"type": "text", "text": "question"},
+ },
+ }}
+ if err := validateUserMessageContent(messages); err != nil {
+ t.Fatalf("valid text content parts rejected: %v", err)
+ }
+}
+
+func TestValidateUserMessageContentRejectsNil(t *testing.T) {
+ messages := []map[string]interface{}{{"role": "user", "content": nil}}
+ if err := validateUserMessageContent(messages); err == nil || !strings.Contains(err.Error(), "messages[0].content") {
+ t.Fatalf("validation error = %v, want indexed missing-content error", err)
+ }
+}
+
func TestAsyncChatRejectsUnauthorizedDatasetsBeforeStartingPipeline(t *testing.T) {
db := setupChatRESTUpdateServiceTestDB(t)
insertForeignPrivateDatasetForChatTest(t, db)
diff --git a/test/integration/wiki/test_wiki_incremental.py b/test/integration/wiki/test_wiki_incremental.py
index 59baad76e5..c8165b4a16 100644
--- a/test/integration/wiki/test_wiki_incremental.py
+++ b/test/integration/wiki/test_wiki_incremental.py
@@ -28,7 +28,7 @@ Run:
test/integration/wiki/test_wiki_incremental.py -s -v
Env:
- RAGFLOW_API_KEY default ragflow-Unleq1d1mMvztQH2QswdjfWZvP9Xkh-TAMhf_XrM7gc
+ RAGFLOW_API_KEY required API token
RAGFLOW_HOST default http://localhost:9380
WIKI_PIPELINE_ID default 977f06ac8ccf11f192396b1c282a3cb7 (wikipipeline)
"""
@@ -39,12 +39,12 @@ import time
import pytest
import requests
-API_KEY = os.getenv(
- "RAGFLOW_API_KEY",
- "ragflow-Unleq1d1mMvztQH2QswdjfWZvP9Xkh-TAMhf_XrM7gc",
-)
+API_KEY = os.getenv("RAGFLOW_API_KEY")
HOST = os.getenv("RAGFLOW_HOST", "http://localhost:9380")
PIPELINE_ID = os.getenv("WIKI_PIPELINE_ID", "977f06ac8ccf11f192396b1c282a3cb7")
+if not API_KEY:
+ pytest.skip("RAGFLOW_API_KEY is required", allow_module_level=True)
+
API = f"{HOST}/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
diff --git a/tools/scripts/download_dev_deps.py b/tools/scripts/download_dev_deps.py
index 35f4557956..d81d8758e2 100755
--- a/tools/scripts/download_dev_deps.py
+++ b/tools/scripts/download_dev_deps.py
@@ -158,9 +158,17 @@ PDF_OXIDE_ASSETS = {
}
+GH_PROXY_URL = "https://gh-proxy.com/"
+
+
def gh_proxy() -> str:
- """GitHub release proxy prefix (gh-proxy.com behind the GFW), else empty."""
- return os.environ.get("GH_PROXY") or ""
+ """Return the supported GitHub proxy prefix, rejecting arbitrary hosts."""
+ proxy = (os.environ.get("GH_PROXY") or "").strip()
+ if not proxy:
+ return ""
+ if proxy.rstrip("/") != GH_PROXY_URL.rstrip("/"):
+ raise RuntimeError(f"GH_PROXY must be empty or {GH_PROXY_URL!r}")
+ return GH_PROXY_URL
def go_module_version(module: str, repo_root: str) -> str:
diff --git a/tools/scripts/test_download_dev_deps.py b/tools/scripts/test_download_dev_deps.py
index 9d635f22be..f4095ae8c0 100644
--- a/tools/scripts/test_download_dev_deps.py
+++ b/tools/scripts/test_download_dev_deps.py
@@ -218,6 +218,12 @@ def test_url_builders_honor_gh_proxy(monkeypatch):
assert native.pdf_oxide_url("linux", "arm64").startswith("https://gh-proxy.com/https://github.com/")
+def test_dev_downloader_rejects_untrusted_gh_proxy(monkeypatch):
+ monkeypatch.setenv("GH_PROXY", "https://attacker.invalid/")
+ with pytest.raises(RuntimeError, match="GH_PROXY"):
+ native.gh_proxy()
+
+
@pytest.fixture
def download_server():
class Handler(BaseHTTPRequestHandler):
@@ -484,6 +490,24 @@ def test_image_script_does_not_handle_native_archives():
assert "onnxruntime" not in (img.__doc__ or "").lower()
+def _image_deps_module():
+ deps_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "deps", "download_deps.py")
+ spec = importlib.util.spec_from_file_location("download_deps_image_security", deps_path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def test_image_proxy_is_restricted_to_the_configured_mirror(monkeypatch):
+ image_deps = _image_deps_module()
+ monkeypatch.setenv("GH_PROXY", "https://attacker.invalid/")
+ with pytest.raises(RuntimeError, match="GH_PROXY"):
+ image_deps.gh_proxy()
+
+ monkeypatch.setenv("GH_PROXY", "https://gh-proxy.com/")
+ assert image_deps.gh_proxy() == "https://gh-proxy.com/"
+
+
# ── Documentation contract: ARM64 build-host minimums ─────────────────────
# The ARM64 host requirements are empirical findings from real hardware
# (glibc 2.38 __isoc23_* symbols, GCC 13 libstdc++, SIMDe headers, cmake 4.x,
diff --git a/web/src/pages/user-setting/data-source/constant/bitbucket-constant.tsx b/web/src/pages/user-setting/data-source/constant/bitbucket-constant.tsx
index 7379ded83d..3f09f6a6f8 100644
--- a/web/src/pages/user-setting/data-source/constant/bitbucket-constant.tsx
+++ b/web/src/pages/user-setting/data-source/constant/bitbucket-constant.tsx
@@ -84,7 +84,6 @@ export const bitbucketConstant = (t: TFunction) => [
},
shouldRender: (formValues: any) => {
const index_mode = formValues?.config?.index_mode;
- console.log('formValues.config', formValues?.config);
return index_mode === 'projects';
},
tooltip: t('setting.bitbucketProjectsTip'),
diff --git a/web/src/pages/user-setting/data-source/constant/confluence-constant.tsx b/web/src/pages/user-setting/data-source/constant/confluence-constant.tsx
index d8adcfcaf0..31dd8d7126 100644
--- a/web/src/pages/user-setting/data-source/constant/confluence-constant.tsx
+++ b/web/src/pages/user-setting/data-source/constant/confluence-constant.tsx
@@ -60,7 +60,6 @@ export const confluenceConstant = (t: TFunction) => [
type: FormFieldType.Text,
customValidate: (val: string, formValues: any) => {
const index_mode = formValues?.config?.index_mode;
- console.log('index_mode', index_mode, val);
if (!val && index_mode === 'page') {
return t('setting.dataSourceValidationFieldRequired', {
label: t('setting.dataSourceFieldPageId'),
diff --git a/web/src/pages/user-setting/data-source/constant/s3-constant.tsx b/web/src/pages/user-setting/data-source/constant/s3-constant.tsx
index 9402ac95b6..68df606a5d 100644
--- a/web/src/pages/user-setting/data-source/constant/s3-constant.tsx
+++ b/web/src/pages/user-setting/data-source/constant/s3-constant.tsx
@@ -89,7 +89,6 @@ export const S3Constant = (t: TFunction) => [
customValidate: (val: string, formValues: any) => {
const authMode = formValues?.config?.credentials?.authentication_method;
const bucketType = formValues?.config?.bucket_type;
- console.log('authMode', authMode, val);
if (
!val &&
(authMode === 'access_key' || bucketType === 's3_compatible')