fix: add authentication to Flask server mutating endpoints (CWE-306)#1388
Open
sebastiondev wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: add authentication to Flask server mutating endpoints (CWE-306)#1388sebastiondev wants to merge 1 commit intomicrosoft:mainfrom
sebastiondev wants to merge 1 commit intomicrosoft:mainfrom
Conversation
All mutating endpoints (/upload, /receive, /control, /user_interaction/submit) now require a Bearer token via the Authorization header. The token is read from the UI_API_TOKEN environment variable; when not set, a random token is generated at startup and logged to the console. Additionally: - Default bind address changed from 0.0.0.0 to 127.0.0.1. - Scenario parameter validated against an explicit allowlist before any processing in the /upload endpoint. - Token comparison uses secrets.compare_digest to prevent timing attacks. Read-only endpoints (/, /traces, /test, /trace, /stdout, static files) remain accessible without authentication. CWE-94 / CWE-306
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability Summary
CWE: CWE-306 (Missing Authentication for Critical Function)
Severity: High
Affected file:
rdagent/log/server/app.pyData Flow
0.0.0.0:19899(all network interfaces) with wildcard CORS (CORS(app)— no origin restriction)./upload,/receive,/control,/user_interaction/submit— have zero authentication: nologin_required, no API token, no bearer check.POST /upload— spawnmultiprocessing.Processinstances that run rdagent pipelines, consuming LLM API keys (financial impact).POST /receive— inject arbitrary messages into traces (integrity compromise).POST /control— stop any running agent process (denial of service).POST /user_interaction/submit— inject user-interaction responses, manipulating agent decision-making.Preconditions
Network access to port 19899. Since the server binds
0.0.0.0, any peer on the same LAN, VPC, or Wi-Fi network can reach it. This does not require shell access to the host — network access alone only grants read-only UI viewing; the unauthenticated endpoints are what grant write/control capabilities.Fix Description & Rationale
This PR applies four defence-in-depth measures:
@require_authdecorator on all 4 mutating endpointsAuthorization: Bearer <token>header. Usessecrets.compare_digestto prevent timing attacks.UI_API_TOKENenv var is unset0.0.0.0to127.0.0.1hostparameter for explicit override._VALID_SCENARIOSfrozenset)scenarioparameter against known values before any filesystem operations or process spawning.Files Changed (4 files, minimal diff)
rdagent/log/server/app.py— auth decorator, token config, bind address, scenario whitelist, trace history loadingtests/test_cwe94_unauthenticated_upload.py— regression tests validating auth enforcementweb/src/utils/api.js— newgetHistoryTraceIds()helper for/tracesendpointweb/src/views/Playground.vue— load history traces from backend (supports the new/tracesread-only endpoint)Test Results Summary
The test file
tests/test_cwe94_unauthenticated_upload.pycovers:test_upload_no_auth_spawns_process/uploadreturns 401 without tokentest_receive_no_auth_injects_messages/receivereturns 401 without tokentest_control_no_auth_stops_process/controlreturns 401 without tokentest_user_interaction_no_auth/user_interaction/submitreturns 401 without tokentest_upload_with_valid_token/uploadreturns 200 with valid Bearer tokentest_read_only_endpoints_accessible/tracesand/testremain accessible without authDisprove Analysis Results
We conducted a systematic attempt to invalidate this finding:
Authentication Check
The original
app.py(commit471eb30) has zero authentication on any endpoint. Nologin_required,@auth,Bearer,api_key, or token checks exist.Network Exposure Check
0.0.0.0:19899— all interfacesCORS(app)with no arguments = wildcard CORS (all origins allowed)Deployment Check
No Dockerfile specifically for the web server. README says
rdagent server_ui --port 19899. No evidence of reverse proxy, VPN, or service mesh requirements. The server is intended for direct usage.Precondition Equivalence Analysis
Conclusion: Network access alone is read-only. The vulnerability grants full write/control access. Not redundant.
Exploit Sketch
Fix Adequacy
The fix addresses the core issue comprehensively. No parallel path bypasses the auth decorator. The auto-generated token prevents "open by default." The bind address change reduces network exposure.
Mitigations Already Present (Insufficient)
secure_filename+commonpathon uploads (file-path safety only)Similar Vulnerabilities Found
rdagent/log/server/debug_app.pyhas identical unauthenticated endpoints (separate debug file, not addressed here)rdagent/scenarios/rl/autorl_bench/core/server.pyalso binds0.0.0.0Verdict: CONFIRMED_VALID (High Confidence)
Notes
fix/cwe306-app-unauthenti-6787,fix/cwe306-app-unauthenti-b618). This branch is the most complete, adding auto-token generation, bind address hardening, and scenario whitelisting.debug_app.pyas follow-ups.📚 Documentation preview 📚: https://RDAgent--1388.org.readthedocs.build/en/1388/