fix: restrict importlib provider loading to trusted namespaces (#7463)
Some checks failed
Checks / format (push) Has been cancelled
Checks / lint (push) Has been cancelled
Checks / mypy (./packages/agbench) (push) Has been cancelled
Checks / mypy (./packages/autogen-agentchat) (push) Has been cancelled
Checks / mypy (./packages/autogen-core) (push) Has been cancelled
Checks / mypy (./packages/autogen-ext) (push) Has been cancelled
Checks / mypy (./packages/magentic-one-cli) (push) Has been cancelled
Checks / docs-mypy (push) Has been cancelled
Checks / pyright (./packages/agbench) (push) Has been cancelled
Checks / pyright (./packages/autogen-agentchat) (push) Has been cancelled
Checks / pyright (./packages/autogen-core) (push) Has been cancelled
Checks / pyright (./packages/autogen-ext) (push) Has been cancelled
Checks / pyright (./packages/magentic-one-cli) (push) Has been cancelled
Checks / test (./packages/autogen-agentchat) (push) Has been cancelled
Checks / test (./packages/autogen-core) (push) Has been cancelled
Checks / test (./packages/autogen-ext) (push) Has been cancelled
Checks / test-grpc (push) Has been cancelled
Checks / test-autogen-ext-pwsh (push) Has been cancelled
Checks / docs (push) Has been cancelled
Checks / docs-example-check (push) Has been cancelled
Checks / samples-code-check (push) Has been cancelled
Checks / markdown-code-lint (push) Has been cancelled
Checks / check-proto-changes-python (push) Has been cancelled
CodeQL Advanced / Analyze (csharp) (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.0 poe-dir:./packages/autogen-core ref:v0.4.0.post1 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.1 poe-dir:./packages/autogen-core ref:v0.4.1 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.2 poe-dir:./packages/autogen-core ref:v0.4.2 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.3 poe-dir:./packages/autogen-core ref:v0.4.3 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.4 poe-dir:./packages/autogen-core ref:v0.4.4 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.5 poe-dir:./packages/autogen-core ref:python-v0.4.5 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.6 poe-dir:./packages/autogen-core ref:python-v0.4.6 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.7 poe-dir:./packages/autogen-core ref:python-v0.4.7 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.8 poe-dir:./packages/autogen-core ref:python-v0.4.8 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.4.9 poe-dir:./packages/autogen-core ref:python-v0.4.9-website sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.1 poe-dir:./packages/autogen-core ref:python-v0.5.1 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.2 poe-dir:./packages/autogen-core ref:python-v0.5.2 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.3 poe-dir:./packages/autogen-core ref:python-v0.5.3 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.4 poe-dir:./packages/autogen-core ref:python-v0.5.4 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.5 poe-dir:./packages/autogen-core ref:python-v0.5.5 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.6 poe-dir:./packages/autogen-core ref:python-v0.5.6 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.5.7 poe-dir:./packages/autogen-core ref:python-v0.5.7 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.6.1 poe-dir:./packages/autogen-core ref:python-v0.6.1 sphinx-release-override: uv-version:0.5.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.6.2 poe-dir:./packages/autogen-core ref:python-v0.6.2 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.6.4 poe-dir:. ref:python-v0.6.4 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.7.1 poe-dir:. ref:python-v0.7.1.post1 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.7.2 poe-dir:. ref:python-v0.7.2 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.7.3 poe-dir:. ref:python-v0.7.3 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.7.4 poe-dir:. ref:python-v0.7.4 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:0.7.5 poe-dir:. ref:python-v0.7.5 sphinx-release-override: uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:dev poe-dir:. ref:${{github.ref}} sphinx-release-override:dev uv-version:0.7.13]) (push) Has been cancelled
Docs / build-04 (map[dest-dir:stable poe-dir:. ref:python-v0.7.5 sphinx-release-override:stable uv-version:0.7.13]) (push) Has been cancelled
Docs / gen-redirects (push) Has been cancelled
Docs / gen-component-schema (push) Has been cancelled
Docs / build-02 (push) Has been cancelled
Docs / build-04-dotnet (push) Has been cancelled
dotnet-ci / paths-filter (push) Has been cancelled
Mem0 Memory Tests / test (push) Has been cancelled
Redis Memory Tests / test (push) Has been cancelled
Checks / codecov (./packages/autogen-agentchat) (push) Has been cancelled
Checks / codecov (./packages/autogen-core) (push) Has been cancelled
Checks / codecov (./packages/autogen-ext) (push) Has been cancelled
Checks / codecov (autogen-ext-grpc) (push) Has been cancelled
Docs / deploy (push) Has been cancelled
dotnet-ci / Dotnet Build & Test (macos-latest, 3.11) (push) Has been cancelled
dotnet-ci / Dotnet Build & Test (ubuntu-latest, 3.11) (push) Has been cancelled
dotnet-ci / integration-test (ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-ci / aot-test (ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-ci / Run openai test (push) Has been cancelled
dotnet-ci / Publish to nightly feeds (push) Has been cancelled

This commit is contained in:
Victor Dibia
2026-03-25 20:15:37 -07:00
committed by GitHub
parent b0477309d2
commit 8544314fa6
6 changed files with 102 additions and 3 deletions

View File

@@ -152,6 +152,12 @@ For more advanced multi-agent orchestrations and workflows, read
Use AutoGen Studio to prototype and run multi-agent workflows without writing code.
> **Caution**: AutoGen Studio is meant to help you rapidly prototype multi-agent workflows and
> demonstrate an example of end user interfaces built with AutoGen. It is **not meant to be a
> production-ready app**. Developers are encouraged to use the AutoGen framework to build their own
> applications, implementing authentication, security and other features required for deployed
> applications. See the [security note](https://microsoft.github.io/autogen/dev/user-guide/autogenstudio-user-guide/index.html#a-note-on-security) for more details.
```bash
# Run AutoGen Studio on http://localhost:8080
autogenstudio ui --port 8080 --appdir ./my-app

View File

@@ -7,6 +7,10 @@ myst:
# Installation
```{caution}
AutoGen Studio is meant to help you rapidly prototype multi-agent workflows and demonstrate an example of end user interfaces built with AutoGen. It is not meant to be a production-ready app. Developers are encouraged to use the AutoGen framework to build their own applications, implementing authentication, security and other features required for deployed applications.
```
There are two ways to install AutoGen Studio - from PyPi or from source. We **recommend installing from PyPi** unless you plan to modify the source code.
## Create a Virtual Environment (Recommended)

View File

@@ -52,6 +52,34 @@ WELL_KNOWN_PROVIDERS = {
"OllamaChatCompletionClient": "autogen_ext.models.ollama.OllamaChatCompletionClient",
}
_TRUSTED_PROVIDER_NAMESPACES: tuple[str, ...] = (
"autogen_core.",
"autogen_agentchat.",
"autogen_ext.",
"autogen_studio.",
"autogenstudio.",
"autogen_test_utils.",
)
def _get_trusted_namespaces() -> tuple[str, ...]:
"""Return the set of trusted provider namespaces.
The default set covers all first-party AutoGen packages. Additional namespaces
can be added at runtime by setting the ``AUTOGEN_ALLOWED_PROVIDER_NAMESPACES``
environment variable to a comma-separated list of package prefixes
(e.g. ``mycompany_agents,mypackage``).
"""
import os
extra = os.environ.get("AUTOGEN_ALLOWED_PROVIDER_NAMESPACES", "")
if extra:
extras = tuple(
ns.strip() if ns.strip().endswith(".") else ns.strip() + "." for ns in extra.split(",") if ns.strip()
)
return _TRUSTED_PROVIDER_NAMESPACES + extras
return _TRUSTED_PROVIDER_NAMESPACES
class ComponentFromConfig(Generic[FromConfigT]):
@classmethod
@@ -224,6 +252,23 @@ class ComponentLoader:
raise ValueError("Invalid")
module_path, class_name = output
trusted = _get_trusted_namespaces()
# Also allow test modules (pytest convention) to load components
module_name = module_path.rsplit(".", maxsplit=1)[-1]
is_test_module = module_name.startswith("test_") or module_path.startswith("test_")
if not is_test_module and not any(
module_path.startswith(ns) or module_path == ns.rstrip(".") for ns in trusted
):
raise ValueError(
f"Provider module '{module_path}' is not in a trusted namespace. "
f"Allowed namespaces by default: autogen_core, autogen_agentchat, autogen_ext, "
f"autogen_studio, autogenstudio. "
f"To allow additional namespaces, set the AUTOGEN_ALLOWED_PROVIDER_NAMESPACES "
f"environment variable to a comma-separated list "
f"(e.g. AUTOGEN_ALLOWED_PROVIDER_NAMESPACES=mycompany_agents,mypackage)."
)
module = importlib.import_module(module_path)
component_class = module.__getattribute__(class_name)

View File

@@ -367,3 +367,19 @@ def test_component_descriptions() -> None:
assert ComponentWithDocstring("test").dump_component().description == "A component using just docstring."
assert ComponentWithDescription("test").dump_component().description == "Explicit description"
assert ComponentWithDescription("test").dump_component().label == "Custom Component"
def test_untrusted_provider_rejected() -> None:
"""load_component must reject providers outside trusted namespaces."""
bad_model = ComponentModel(provider="os.path.join", config={})
with pytest.raises(ValueError, match="not in a trusted namespace"):
ComponentLoader.load_component(bad_model, object) # type: ignore
def test_trusted_provider_via_env_var(monkeypatch: pytest.MonkeyPatch) -> None:
"""AUTOGEN_ALLOWED_PROVIDER_NAMESPACES extends the allowed namespace list."""
monkeypatch.setenv("AUTOGEN_ALLOWED_PROVIDER_NAMESPACES", "mycompany_agents")
from autogen_core._component_config import _get_trusted_namespaces # type: ignore
namespaces = _get_trusted_namespaces()
assert "mycompany_agents." in namespaces

View File

@@ -16,10 +16,27 @@ def extract_audio(video_path: str, audio_output_path: str) -> str:
"""
Extracts audio from a video file and saves it as an MP3 file.
:param video_path: Path to the video file.
:param audio_output_path: Path to save the extracted audio file.
:param video_path: Path to the video file (must be a local file path, not a URL).
:param audio_output_path: Path to save the extracted audio file (must end with .mp3).
:return: Confirmation message with the path to the saved audio file.
"""
import os
import re
# Reject URLs to prevent SSRF via ffmpeg
if re.match(r"^[a-zA-Z][a-zA-Z0-9+\-.]*://", video_path):
raise ValueError("video_path must be a local file path, not a URL.")
# Enforce .mp3 extension to prevent writing arbitrary file types
if not audio_output_path.lower().endswith(".mp3"):
raise ValueError("audio_output_path must end with .mp3.")
# Prevent path traversal — output must stay within the current working directory
cwd = os.path.realpath(os.getcwd())
output_real = os.path.realpath(audio_output_path)
if not output_real.startswith(cwd + os.sep) and output_real != cwd:
raise ValueError("audio_output_path must be within the current working directory.")
(ffmpeg.input(video_path).output(audio_output_path, format="mp3").run(quiet=True, overwrite_output=True)) # type: ignore
return f"Audio extracted and saved to {audio_output_path}."

View File

@@ -9,8 +9,19 @@ AutoGen Studio is an AutoGen-powered AI app (user interface) to help you rapidly
Code for AutoGen Studio is on GitHub at [microsoft/autogen](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-studio)
> [!CAUTION]
> AutoGen Studio is meant to help you rapidly prototype multi-agent workflows and demonstrate an example of end user interfaces built with AutoGen. It is **not meant to be a production-ready app**. Developers are encouraged to use the [AutoGen framework](https://microsoft.github.io/autogen) to build their own applications, implementing authentication, security and other features required for deployed applications.
> [!WARNING]
> AutoGen Studio is under active development and is currently not meant to be a production-ready app. Expect breaking changes in upcoming releases. [Documentation](https://microsoft.github.io/autogen/docs/autogen-studio/getting-started) and the `README.md` might be outdated.
> AutoGen Studio is under active development. Expect breaking changes in upcoming releases.
## A Note on Security
AutoGen Studio is a research prototype and is **not meant to be used** in a production environment. Some baseline practices are encouraged e.g., using Docker code execution environment for your agents.
However, other considerations such as rigorous tests related to jailbreaking, ensuring LLMs only have access to the right keys of data given the end user's permissions, and other security features are not implemented in AutoGen Studio.
If you are building a production application, please use the [AutoGen framework](https://microsoft.github.io/autogen) and implement the necessary security features.
## Updates