Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore(api): enhance ruff rules to disallow dangerous functions and modules (#16461)

QuantumGhost383af7bf7644
diff --git a/api/.ruff.toml b/api/.ruff.toml
index f058731ada5..41a24abad95 100644
--- a/api/.ruff.toml
+++ b/api/.ruff.toml
@@ -37,6 +37,12 @@ select = [
"UP", # pyupgrade rules
"W191", # tab-indentation
"W605", # invalid-escape-sequence
+ # security related linting rules
+ # RCE proctection (sort of)
+ "S102", # exec-builtin, disallow use of `exec`
+ "S307", # suspicious-eval-usage, disallow use of `eval` and `ast.literal_eval`
+ "S301", # suspicious-pickle-usage, disallow use of `pickle` and its wrappers.
+ "S302", # suspicious-marshal-usage, disallow use of `marshal` module
]
ignore = [
diff --git a/api/models/dataset.py b/api/models/dataset.py
index 28589eb8c16..f104c32b53b 100644
--- a/api/models/dataset.py
+++ b/api/models/dataset.py
@@ -910,7 +910,7 @@ class Embedding(db.Model): # type: ignore[name-defined]
self.embedding = pickle.dumps(embedding_data, protocol=pickle.HIGHEST_PROTOCOL)
def get_embedding(self) -> list[float]:
- return cast(list[float], pickle.loads(self.embedding))
+ return cast(list[float], pickle.loads(self.embedding)) # noqa: S301
class DatasetCollectionBinding(db.Model): # type: ignore[name-defined]