REST API Surface
Overview
The MobSF REST API surface is implemented by view functions under mobsf/MobSF/views/api/ and mounted from mobsf/…/urls.py under /api/v1/.... mobsf/…/api_middleware.py provides the shared response wrapper and the API-key middleware; every endpoint in the API view modules is also decorated with @csrf_exempt and @request_method(...), so API clients use form-style request.POST parameters without CSRF tokens while still being constrained to the method declared by each view.
Authentication is request-path based. RestApiAuthMiddleware in mobsf/…/api_middleware.py runs for any path beginning with /api/, short-circuits CORS preflight OPTIONS with an empty JSON response, and accepts the API key from either X-Mobsf-Api-Key (HTTP_X_MOBSF_API_KEY) or Authorization (HTTP_AUTHORIZATION). The expected key is resolved by api_key(settings.MOBSF_HOME) in mobsf/…/init.py, which reads MOBSF_API_KEY_FILE, then MOBSF_API_KEY, then a SHA-256 digest of the MobSF home secret file. Responses produced through make_api_response are JSON with wildcard CORS headers, Access-Control-Allow-Methods: POST, and allowed headers for the two auth forms; binary endpoints may return raw HttpResponse objects instead.
Static analysis endpoints live in mobsf/…/api_static_analysis.py and delegate to existing web-view services with an API flag rather than implementing analysis locally. Uploads call Upload(request).upload_api(), recent scans call RecentScans(request).recent_scans(), search calls search(request, api=True), and delete calls delete_scan(request, True). api_scan requires a hash, validates it as MD5, looks it up in RecentScansDB, then selects the analyzer from settings.ANDROID_EXTS, settings.IOS_EXTS, or settings.WINDOWS_EXTS: Android-like inputs go through StaticAnalyzer.views.android.static_analyzer.static_analyzer, with a fallback to static_analyzer_ios when the Android analyzer returns a response containing type; IPA inputs go directly to static_analyzer_ios; Windows packages go to windows.staticanalyzer_windows. Report endpoints use StaticAnalyzer.views.common.pdf.pdf for both PDF (download_pdf) and JSON (report_json) output; PDF success returns an application/pdf HttpResponse, while JSON success is wrapped through make_api_response. Source viewing dispatches Android-style types (eclipse, studio, flutter, apk, java, smali, xml, js) to StaticAnalyzer.views.android.views.view_source.run and all other types to the iOS source viewer. The same module exposes scan logs, queued tasks, app comparison, scorecard, and suppression CRUD by forwarding to get_scan_logs, list_tasks, compare_apps, appsec_dashboard, and the suppression helpers.
Android dynamic analysis endpoints live in mobsf/…/api_android_dynamic_analysis.py. The /api/v1/dynamic/... group lists apps, starts analysis for a hash, stops analysis, returns dynamic reports, and views captured dynamic files by delegating to DynamicAnalyzer.views.android.dynamic_analyzer, tests_common, report, and DynamicAnalyzer.views.common.device. Stopping analysis is a two-step wrapper: it derives the analysis identifier with tests_common.get_analysis_identifier, collects logs with tests_common.collect_logs, then downloads data with tests_common.download_data. Android device operations under /api/v1/android/... forward to DynamicAnalyzer.views.android.operations for MobSFy, screenshots, ADB execution, root CA actions, and global proxy configuration. Android dynamic tests forward to tests_common.activity_tester, start_activity, and tls_tests. Frida endpoints use both Android test helpers and shared Frida views: instrumentation and runtime dependency resolution call DynamicAnalyzer.views.android.tests_frida, while live logs, script listing, and script content use DynamicAnalyzer.views.common.frida.views.
iOS Corellium-backed dynamic analysis endpoints live in mobsf/…/api_ios_dynamic_analysis.py. The initial dynamic-analysis entrypoint delegates to DynamicAnalyzer.views.ios.dynamic_analyzer.dynamic_analysis; the analyzer step requires instance_id and bundle_id and delegates to dynamic_analyzer.dynamic_analyzer. Corellium instance lifecycle and device-control APIs forward to DynamicAnalyzer.views.ios.corellium_instance: supported model/version discovery, VM creation, start/stop/unpause/reboot/destroy, app listing, environment setup, app run/stop/remove, screenshot, container path lookup, network capture and PCAP download, SSH execution, app-data download, touch/input events, system logs, device file upload/download, and Corellium file/PCAP binary downloads. iOS Frida instrumentation requires instance_id, bundle_id, hash, default_hooks, dump_hooks, auxiliary_hooks, and frida_code, then delegates to DynamicAnalyzer.views.ios.tests_frida.ios_instrument. Corellium dynamic reports call DynamicAnalyzer.views.ios.report.ios_view_report.
Jailbroken physical iOS device endpoints live in mobsf/…/api_ios_device_analysis.py and use device_id instead of Corellium instance_id. They forward dynamic-analysis setup, device discovery, IPA installation, analyzer start, file upload, SSH execution, Frida instrumentation, logs, process listing, file download, API monitor, app-data download, and JSON report generation to DynamicAnalyzer.views.ios.device.dynamic_analyzer or DynamicAnalyzer.views.ios.device.report. File upload is the one endpoint in this module that checks both request.POST['device_id'] and request.FILES['file']; file downloads return the downstream binary response when it carries Content-Disposition.
Across these modules, request/response handling is intentionally thin. Most endpoints validate only presence of required POST keys, return 422 for missing parameters (or missing files where applicable), then inspect simple downstream conventions such as error in resp, resp['status'] == 'ok', resp.get('status') == 'failed', resp.get('data'), resp.get('message'), or Content-Disposition to choose between 200 and 500. The API surface therefore shares state and side effects with the analyzer modules it delegates into: static scan metadata in RecentScansDB, analyzer report artifacts on disk, device/emulator state, Corellium instances, Frida scripts, captured logs, downloaded app data, and generated PDF/JSON reports are all owned by the downstream analyzer services rather than by the API view layer.
Coupling
- If routes are added or renamed in mobsf/…/urls.py, also update the matching view in mobsf/…/*.py and keep the path under
/api/if it must be protected byRestApiAuthMiddleware; middleware authentication is based onrequest.path.startswith('/api/'), not on view membership. - If
make_api_responsein mobsf/…/api_middleware.py changes CORS headers, verify binary-returning endpoints in api_static_analysis.py, api_ios_dynamic_analysis.py, and api_ios_device_analysis.py; PDF, PCAP, and file downloads bypass the JSON wrapper on success and manually preserve only the headers their downstreamHttpResponsealready carries. - If analyzer helpers change their success/error response shapes, update the wrapper checks in the corresponding API module. api_android_dynamic_analysis.py expects Android operation helpers to return
{'status': 'ok'}on success, Frida monitor/log helpers to exposedataormessage, and report/view helpers to signal failures with anerrorkey; api_ios_dynamic_analysis.py and api_ios_device_analysis.py treatstatus == 'failed'as a 500 for most Corellium/device operations. - If static analyzer scan types or extension settings change, verify
api_scanin mobsf/…/api_static_analysis.py; it dispatches fromRecentScansDB.SCAN_TYPEagainstsettings.ANDROID_EXTS,settings.IOS_EXTS, andsettings.WINDOWS_EXTS, so a new extension will not be scanned through the API unless it lands in one of those buckets orapi_scangains a new branch. - If
request_methodbehavior in mobsf/…/helpers.py changes, verify all API views. They rely on that decorator for method enforcement whileRestApiAuthMiddlewareseparately permits unauthenticatedOPTIONSpreflight before the decorators run. - If API key generation or configuration changes in mobsf/…/init.py, verify
api_authin mobsf/…/api_middleware.py; it compares the configured key directly against client headers withcompare_digest, so formatting differences such as bearer prefixes or bytes-vs-string changes will reject every API request.
Risks
- mobsf/…/api_static_analysis.py can raise an unbound local error in
api_scanifRecentScansDB.SCAN_TYPEis not included insettings.ANDROID_EXTS,settings.IOS_EXTS, orsettings.WINDOWS_EXTS, becauseresponseis returned after the extension branches without a default branch. A new upload type that reachesRecentScansDBwithout updating this dispatch will fail at the API layer instead of returning a structured error. - Several endpoints in mobsf/…/api_android_dynamic_analysis.py, api_ios_dynamic_analysis.py, and api_ios_device_analysis.py index downstream dictionaries directly (
resp['status']) or assume specific status strings. If a delegated analyzer returns a different shape on an exception path, the API view can produce a server error beforemake_api_responsecan wrap it. - History for
mobsf/MobSF/views/api/includes multiple hotfix commits touching REST behavior (5b7c5c0realtime scan status/logs,1e93205Corellium stop-app API,bfd8bc2Frida logs response code,941f7c5iOS framework analysis QA,3c2a2f1scan API simplification), which is a signal that route wrappers are sensitive to downstream response contracts. When reviewing API changes, check both the wrapper and the delegated analyzer function even when the API diff is small.