mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-22 11:44:11 -05:00
[PR #14703] [MERGED] feat: Blacklist modules from arbitrary code execution in code interpreter #23562
Reference in New Issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/14703
Author: @rragundez
Created: 6/5/2025
Status: ✅ Merged
Merged: 8/17/2025
Merged by: @tjbck
Base:
dev← Head:code-interpreter-blacklist📝 Commits (2)
6dd9691Add option to blacklist modules in code interpreterbb09245Inject code to block imports from blacklisted modules📊 Changes
2 files changed (+31 additions, -0 deletions)
View changed files
📝
backend/open_webui/config.py(+10 -0)📝
backend/open_webui/utils/middleware.py(+21 -0)📄 Description
At this moment, code interpreter executes any code that the user desires based on a prompt, this PR allows to blacklist Python modules from being used in the code.
Without the use of this blacklist, it exposes a high security risk for obvious reasons but here some examples:
The potential risks are indeed mitigated by using
pyodideas it provides an isolated environment running on the browser but they still exist.The risks become very severe if the setup uses a remote/side-car Jupyter server for executing the code interpreter code. If the developers do not have a medium to high degree of knowledge of network, isolation and UNIX filesystems, the server could be connected to the internal network or be prepared as part of a golden image, and a user, or if an external malicious actor gets access to the app, it could basically take full control of the system or execute lateral movement attacks.
Even though the measures this PR allows are not full proof (the malicious actor could still write its own module as part of the prompt bypassing the use of blacklisted modules), it provides some level of protection.
To be secure, in addition to the measures in this PR, the remote jupyter server should be running in a jailed environment completely disconnected from any network (preferably using a containerised environment) and the permissions on the filesystem should be very restrictive. But these measures are out-of-scope for openwebui, but it could provide a recommendation or a tailored jupyter server image for example that is known to have some of these measures in place.
Below I include some quick examples of the responses with and without the modules restrictions, I am using
pyodidefor testing but you can extrapolate on the potential risks.Without:

In pyodide does not work but it would in a remote jupyter server

WIth:

I did test several times that all works but please have a closer look. The modules I blacklisted for this test are:
CODE_INTERPRETER_BLACKLISTED_MODULES=os, shutil, pathlib, tempfile, glob, fnmatch, subprocess, multiprocessing, sqlite3, email, http, aiohttp, socket, urllib, ftplib, smtplib, imaplib, poplib, telnetlib, xmlrpc, asyncio, ssl, select, webbrowser, sys, requests, pip, importlibIf accepted I will create the required PR in the documentation for this environment variable.
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Added
Changed
Deprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
Screenshots or Videos
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.