CVE-2026-111057 CRITICAL 10.0 난이도Difficulty 입문Intro
쉼표 하나가 지운 차단 규칙: Mercury 터미널 API 인증 우회One missing comma that erased a block rule: Mercury terminal API auth bypass
CVE-2026-111057는 Mercury의 Incorrect Regular Expression(CWE-185) 취약점으로, CVSS 10(CRITICAL)입니다. 영향 버전: 3.0.0 – 3.2.3. 수정 버전: 3.2.4.CVE-2026-111057 is an Incorrect Regular Expression (CWE-185) vulnerability in Mercury, rated CVSS 10 (CRITICAL). Affected: 3.0.0 – 3.2.3. Fixed in: 3.2.4.
| 제품Product | Mercury |
|---|---|
| 영향 버전Affected | 3.0.0 – 3.2.3 |
| 수정 버전Fixed in | 3.2.4 |
| 심각도Severity | CVSS 10 CRITICAL |
| 취약점 유형Weakness | CWE-185 Incorrect Regular Expression |
| 공격 조건Attack conditions | 원격 (네트워크) · 인증 불필요 · 사용자 상호작용 불필요Remote (network) · No authentication · No user interaction |
1. TL;DR
Mercury 는 Jupyter 노트북을 웹 앱·대시보드로 공유하는 Python 프레임워크다. 이 프레임워크는 익명 사용자에게 열면 안 되는 경로를 정규식 목록 BLOCKED_PATTERNS 로 막는다. 어드바이저리에 따르면 이 목록의 첫째 항목 뒤에 쉼표가 빠져 있었다. 그 결과 파이썬이 인접한 두 문자열 리터럴(/lab… 과 /api/terminals…)을 하나로 이어 붙였고, /api/terminals 를 막는 독립 규칙이 사라졌다.
차단을 통과한 요청은 Jupyter Server 의 터미널 API 까지 도달한다. 인증 없는 공격자가 Mercury 프로세스 권한으로 동작하는 대화형 OS 셸을 얻을 수 있다. 영향 버전은 3.0.0 이상 3.2.3 이하이고, 3.2.4 에서 쉼표를 추가해 고쳤다.
이 결함은 메모리 손상이 아니라 “목록 항목 하나가 조용히 사라진” 논리 오류다. 취약점이 복잡한 기법에서만 나오지 않는다는 점을 보여 주는 사례다.
2. Flaw 분류
| 항목 | 값 |
|---|---|
| 1차 CWE | CWE-185 Incorrect Regular Expression (NVD 는 CWE-284 Improper Access Control 도 함께 지정) |
| 공격 벡터 | 네트워크. Mercury 서버에 HTTP 로 도달할 수 있는 모든 클라이언트 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H, 10.0) |
| 영향 | 인증 없는 원격 명령 실행. Mercury 프로세스가 접근 가능한 파일·환경 변수·비밀 정보의 열람과 변조, 서비스 중단 |
| 전제 | 영향 버전(>= 3.0.0, <= 3.2.3)을 쓰고, 공격자가 서버에 네트워크로 접근할 수 있어야 한다. 어드바이저리는 VPN, 리버스 프록시 인증, 방화벽 같은 추가 통제 없이 배포한 경우를 위험하다고 본다. |
3. 근본 원인
3.1 익스플로잇 이전의 구조
Mercury 는 JupyterLab·Jupyter Server 위에 얹힌 애플리케이션이다. Jupyter Server 에는 터미널을 만드는 API 가 내장되어 있다. 익명 방문자에게 대시보드만 보여 주려면, 이런 위험한 내장 경로를 Mercury 쪽에서 막아야 한다. 이 역할을 mercury_app/block_handler.py 의 BLOCKED_PATTERNS 목록이 맡는다. 어드바이저리에 인용된 구조는 다음과 같다.
- JupyterLab UI 와 API 용
/lab…패턴 - 터미널용
/api/terminals…패턴 - 서버 종료용
/api/shutdown…패턴 - 파일 접근용
/files…패턴
3.2 결함: 암묵적 문자열 연결
파이썬은 쉼표 없이 나란히 놓인 문자열 리터럴을 하나의 문자열로 이어 붙인다. 어드바이저리에 따르면 첫째 항목(/lab…) 끝에 쉼표가 없어서 둘째 항목(/api/terminals…)과 합쳐졌다. 목록에는 3개 규칙만 남았고, 합쳐진 패턴은 “/lab… 뒤에 /api/terminals… 가 이어지는” 경로에만 해당한다. 단독 /api/terminals 요청에는 해당하는 규칙이 없다.
문법 오류가 아니라 정상 문법이라 인터프리터도 경고하지 않는다. 목록이 코드상으로는 4줄이어도 실제 항목은 3개가 된다.
3.3 왜 심각해지는가
이 목록은 Mercury 의 유일한 방어선 역할을 했다. 이 목록을 우회하면 그 뒤에 있는 Jupyter Server 의 터미널 API 가 인증 없이 노출된다. 어드바이저리는 이 API 가 “WebSocket 으로 접근하는 실제 OS 셸”을 만든다고 설명한다. CVSS 범위(Scope)가 Changed 인 이유도 여기에 있다. 취약한 구성요소(Mercury 의 차단 목록)가 깨지면서 그보다 넓은 호스트 권한까지 영향을 받는다.
4. 익스플로잇 흐름(개념)
공격자에게 필요한 것은 특수한 입력 문자열이 아니다. 차단되어야 할 경로로 정상적인 형태의 요청을 보내면 된다. 구체적인 요청 형식과 명령은 의도적으로 적지 않는다.
- 차단 목록 정의 — 쉼표 누락
- 두 정규식 리터럴 병합 — 규칙 하나 소실
- 터미널 경로 요청이 차단 검사를 통과
- Jupyter 터미널 API 도달 — OS 셸 세션 생성
- Mercury 프로세스 권한의 명령 실행과 데이터 접근
- 차단 목록 정의: 개발 단계에서 쉼표가 빠진다. 이 시점에는 눈에 띄는 오류가 없다.
- 리터럴 병합: 파이썬이 두 패턴을 하나로 이어 붙여, 터미널 경로를 막는 규칙이 사라진다.
- 검사 통과: 터미널 API 경로로 온 요청이 어떤 차단 규칙에도 해당하지 않는다.
- 내장 API 도달: 요청이 Jupyter Server 의 터미널 API 로 전달되고, 서버가 OS 셸 세션을 연다. 어드바이저리에 따르면 셸에는 WebSocket 으로 연결한다.
- 영향: 공격자는 Mercury 프로세스가 가진 권한으로 명령을 실행하고, 그 프로세스가 읽을 수 있는 데이터에 접근한다.
5. 트리거 조건
- 버전: Mercury 3.0.0 이상 3.2.3 이하 (어드바이저리의 영향 범위).
- 접근성: 공격자가 Mercury 서버에 네트워크로 도달해야 한다. 계정, 세션, 사전 접근은 필요 없다.
- 설정: 어드바이저리 작성자는 기본 설정의 로컬 Docker 배포(Mercury 3.2.3)에서 확인했다고 밝혔다. 이 외의 배포 형태별 차이는 공개 정보로는 확인되지 않음.
- 얻는 권한: 셸 권한은 Mercury 프로세스의 권한과 같다. 어드바이저리의 확인 환경에서는 컨테이너 내부 root 였다. 비특권 사용자로 실행하면 영향 범위가 줄어들 수 있으나, 그 경우의 구체적 영향은 출처에서 확인되지 않음.
- 앞단 통제: 리버스 프록시 인증이나 방화벽이 있으면 노출이 줄어든다. 어드바이저리도 이런 통제 없이 인터넷에 노출한 경우를 위험 상황으로 언급한다.
6. 패치 분석
수정 커밋은 8c46712 “fix: block unauthenticated terminal access”이다. 7개 파일이 바뀌었다. 이 중 4개는 버전을 3.2.3 에서 3.2.4 로 올리는 변경이고, 로직 변경은 mercury_app/block_handler.py 의 한 줄이다. 나머지 하나는 새 테스트 파일이다.
BLOCKED_PATTERNS = [
# JupyterLab UI + API
r"/lab(?!/(?:extensions/|api/settings(?:/|$)|api/translations(?:/|$)))(?:/.*)?"
r"/lab(?!/(?:extensions/|api/settings(?:/|$)|api/translations(?:/|$)))(?:/.*)?",
r"/api/terminals(?:/.*)?",
r"/api/shutdown(?:/.*)?",
r"/files(?:/.*)?",이 줄이 흐름을 끊는 이유는 다음과 같다. 끝에 쉼표를 붙이면 /lab… 과 /api/terminals… 가 서로 다른 리스트 항목이 된다. 리터럴 병합(흐름의 2단계)이 일어나지 않고, 터미널 경로는 다시 독립된 차단 규칙에 걸린다.
같은 커밋에서 추가된 mercury/tests/test_block_handler.py 는 다음 동작을 검증한다.
/api/terminals와/api/terminals/1이 차단된다./lab/api/settings등 일부 허용 경로는 차단되지 않는다./lab,/api/shutdown,/files/…는 차단된다.
이 회귀 테스트는 이 유형의 실수를 가장 직접적으로 막는 방법이다. 이 수정은 목록의 오타를 바로잡는 것이다. 허용 목록(allowlist) 방식 등으로 설계를 바꾸는 변경은 이 커밋에 없다.
수정 릴리스는 v3.2.4다. 릴리스 노트는 인증 없는 터미널 접근에 대한 패치라고 밝히고 어드바이저리를 가리킨다.
7. 탐지·완화
즉시 조치
- Mercury 를 3.2.4 이상으로 업그레이드한다. 영향 버전은 3.0.0 이상 3.2.3 이하다.
- 업그레이드 전에는 인터넷에서 직접 접근할 수 없게 한다. 리버스 프록시 인증, VPN, 방화벽 중 하나 이상을 둔다.
- 영향 버전을 외부에 노출한 적이 있다면 침해를 가정한다. 해당 프로세스가 읽을 수 있던 환경 변수·API 키·자격 증명은 교체를 검토한다.
- Mercury 프로세스는 비특권 사용자로 실행하고, 컨테이너에는 필요한 파일과 비밀만 마운트한다.
탐지
- 웹 서버나 프록시 로그에서
/api/terminals와 터미널 WebSocket 경로(/terminals/websocket/…)에 대한 요청을 찾는다. 정상적인 익명 사용에서는 나올 이유가 없는 경로다. - Mercury 프로세스의 자식으로 셸이 생성되는 이력을 점검한다. 터미널 API 가 악용되면 이런 흔적이 남을 것으로 추정되나, 구체적 흔적은 공개 정보로는 확인되지 않음.
- 개발 측면에서는 정규식·경로 목록을 리스트로 쓸 때 암묵적 문자열 연결을 린터로 잡는다. pylint 의 implicit-str-concat 이나 Ruff 의 ISC 계열 규칙이 이런 용도로 쓰인다. 차단 목록 같은 보안 설정은 “차단되어야 할 경로가 실제로 차단되는지”를 확인하는 테스트로 보호한다.
격리된 실습(로컬 Docker 랩)
- 재현은 인터넷과 분리된 로컬 Docker 랩에서만 한다. 외부로 나가는 네트워크를 끊고, 호스트 디렉터리나 실제 비밀은 마운트하지 않는다. 남의 서버나 운영 환경에서는 시도하지 않는다.
- 학습 목표는 공격 성공이 아니라 “리터럴 병합으로 규칙이 사라지는 과정”을 이해하는 것이다. 3.2.3 과 3.2.4 의
block_handler.py를 비교하고, 커밋에 추가된test_block_handler.py를 두 버전에 각각 실행해 결과 차이를 확인하는 방식을 권한다. - 파이썬 REPL 에서 쉼표가 있는 리스트와 없는 리스트의
len()을 비교해 보는 것도 좋은 연습이다. 줄 수와 실제 항목 수가 달라진다는 점이 핵심이다.
8. References
1. TL;DR
Mercury is a Python framework for sharing Jupyter notebooks as web apps and dashboards. It blocks paths that must not be open to anonymous users with a list of regular expressions, BLOCKED_PATTERNS. According to the advisory, a comma was missing after the first entry in that list. As a result Python joined two adjacent string literals (/lab… and /api/terminals…) into one, and the standalone rule that blocked /api/terminals disappeared.
A request that gets past the block list reaches Jupyter Server’s terminal API. An unauthenticated attacker can obtain an interactive OS shell running with the Mercury process’s privileges. Affected versions are 3.0.0 through 3.2.3, and 3.2.4 fixed it by adding the comma.
This flaw is not memory corruption — it is a logic error where “a single list entry quietly vanished.” It shows that vulnerabilities don’t only come from sophisticated techniques.
2. Flaw classification
| Item | Value |
|---|---|
| Primary CWE | CWE-185 Incorrect Regular Expression (NVD also assigns CWE-284 Improper Access Control) |
| Attack vector | Network. Any client that can reach the Mercury server over HTTP (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H, 10.0) |
| Impact | Unauthenticated remote command execution. Read and tamper with files, environment variables, and secrets reachable by the Mercury process, plus denial of service |
| Prerequisites | Running an affected version (>= 3.0.0, <= 3.2.3) and the attacker can reach the server over the network. The advisory treats a deployment without additional controls — VPN, reverse-proxy auth, firewall — as dangerous. |
3. Root cause
3.1 The structure before exploitation
Mercury is an application layered on top of JupyterLab and Jupyter Server. Jupyter Server ships a built-in API for creating terminals. To show anonymous visitors only the dashboard, Mercury has to block these dangerous built-in paths on its side. The BLOCKED_PATTERNS list in mercury_app/block_handler.py plays that role. The structure cited in the advisory is:
/lab…patterns for the JupyterLab UI and API- the
/api/terminals…pattern for terminals - the
/api/shutdown…pattern for server shutdown - the
/files…pattern for file access
3.2 The flaw: implicit string concatenation
Python joins string literals placed side by side without a comma into a single string. According to the advisory, there was no comma at the end of the first entry (/lab…), so it merged with the second entry (/api/terminals…). Only 3 rules remained in the list, and the merged pattern only matches a path where “/api/terminals… follows /lab….” A standalone /api/terminals request matches no rule.
This is valid syntax, not a syntax error, so the interpreter raises no warning. Even though the list is 4 lines in the source, it has 3 actual entries.
3.3 Why it becomes severe
This list served as Mercury’s only line of defense. Bypassing it exposes Jupyter Server’s terminal API behind it, without authentication. The advisory explains that this API creates “a real OS shell accessed over WebSocket.” This is also why the CVSS Scope is Changed: when the vulnerable component (Mercury’s block list) breaks, the impact extends to the broader host privileges.
4. Exploit flow (conceptual)
The attacker needs no special input string. They just send a normally shaped request to a path that should have been blocked. The concrete request format and commands are deliberately omitted.
- Block list defined — comma omitted
- Two regex literals merge — one rule lost
- Terminal-path request passes the block check
- Reaches Jupyter terminal API — OS shell session created
- Command execution and data access at Mercury process privileges
- Block list defined: a comma is dropped during development. There is no visible error at this point.
- Literals merge: Python joins the two patterns into one, and the rule blocking the terminal path disappears.
- Check passes: a request to the terminal API path matches none of the block rules.
- Reaches the built-in API: the request is forwarded to Jupyter Server’s terminal API, and the server opens an OS shell session. According to the advisory, the shell is connected over WebSocket.
- Impact: the attacker runs commands with the privileges held by the Mercury process and accesses data that process can read.
5. Trigger conditions
- Version: Mercury 3.0.0 through 3.2.3 (the affected range in the advisory).
- Reachability: the attacker must reach the Mercury server over the network. No account, session, or prior access is needed.
- Configuration: the advisory authors confirmed it on a default-configuration local Docker deployment (Mercury 3.2.3). Differences across other deployment shapes are not confirmed in public sources.
- Privileges gained: the shell’s privileges equal those of the Mercury process. In the advisory’s confirmed environment it was root inside the container. Running as a non-privileged user may reduce the impact, but the concrete impact in that case is not confirmed in the sources.
- Front-end controls: reverse-proxy authentication or a firewall reduces exposure. The advisory, too, calls out exposure to the internet without such controls as the risky scenario.
6. Patch analysis
The fix commit is 8c46712 “fix: block unauthenticated terminal access”. Seven files changed. Four of them bump the version from 3.2.3 to 3.2.4, the logic change is one line in mercury_app/block_handler.py, and the remaining one is a new test file.
BLOCKED_PATTERNS = [
# JupyterLab UI + API
r"/lab(?!/(?:extensions/|api/settings(?:/|$)|api/translations(?:/|$)))(?:/.*)?"
r"/lab(?!/(?:extensions/|api/settings(?:/|$)|api/translations(?:/|$)))(?:/.*)?",
r"/api/terminals(?:/.*)?",
r"/api/shutdown(?:/.*)?",
r"/files(?:/.*)?",Here is why this line breaks the chain. Adding a comma at the end makes /lab… and /api/terminals… separate list entries. Literal merging (step 2 of the flow) no longer happens, and the terminal path is once again caught by an independent block rule.
The same commit adds mercury/tests/test_block_handler.py, which verifies:
/api/terminalsand/api/terminals/1are blocked.- Some allowed paths, such as
/lab/api/settings, are not blocked. /lab,/api/shutdown, and/files/…are blocked.
This regression test is the most direct way to prevent this class of mistake. The fix corrects a typo in the list; there is no change in this commit that redesigns the approach (for example, switching to an allowlist).
The fixed release is v3.2.4. The release notes state it is a patch for unauthenticated terminal access and point to the advisory.
7. Detection & mitigation
Immediate actions
- Upgrade Mercury to 3.2.4 or later. Affected versions are 3.0.0 through 3.2.3.
- Until you upgrade, make it unreachable directly from the internet. Put at least one of reverse-proxy authentication, VPN, or firewall in front of it.
- If you ever exposed an affected version externally, assume compromise. Review rotating any environment variables, API keys, and credentials the process could read.
- Run the Mercury process as a non-privileged user, and mount only the files and secrets the container needs.
Detection
- Look in web server or proxy logs for requests to
/api/terminalsand the terminal WebSocket path (/terminals/websocket/…). Normal anonymous use has no reason to hit those paths. - Check for a history of shells spawned as children of the Mercury process. Such traces are expected if the terminal API is abused, but the concrete indicators are not confirmed in public sources.
- On the development side, catch implicit string concatenation when writing regex or path lists with a linter. pylint’s implicit-str-concat or Ruff’s ISC-family rules serve this purpose. Protect security settings like block lists with tests that confirm “the paths that must be blocked are actually blocked.”
Isolated practice (local Docker lab)
- Reproduce only in a local Docker lab isolated from the internet. Cut outbound networking, and do not mount host directories or real secrets. Do not attempt this against someone else’s server or a production environment.
- The learning goal is not a successful attack but understanding “how a rule disappears through literal merging.” We recommend comparing
block_handler.pybetween 3.2.3 and 3.2.4, and running thetest_block_handler.pyadded in the commit against each version to see the difference in results. - Comparing
len()of a list with and without the comma in a Python REPL is also a good exercise. The key point is that the line count and the actual entry count diverge.