AGENTS.md · MobSF/Mobile-Security-Framework-MobSF
AGENTS.md from MobSF/Mobile-Security-Framework-MobSF: 245 lines covering Code Quality — Mandatory Before Every Commit, Security Architecture, Past…
Template by MobSF
Install
Works with Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Claude Code. Read the repository before you give any tool access to your data.
curl -fsSL https://raw.githubusercontent.com/MobSF/Mobile-Security-Framework-MobSF/master/AGENTS.md -o AGENTS.md
Read it and adapt it to your project before use.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: prompt-engineering
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
What's in it
An AGENTS.md file: instructions coding agents (Codex, Cursor, Copilot, Gemini CLI and others) read before working in a repo.
- For
- Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Claude Code
- Length
- 245 lines
- File
AGENTS.md
Sections
- Code Quality — Mandatory Before Every Commit
- Security Architecture
- Past Vulnerabilities and Insecure Patterns
- Incomplete Fix Anti-Pattern
- Input Trust Model
- Django-Specific Security Features
- Archive Extraction Safety
- Import Conventions
- Checklist for Any Change That Touches File I/O or User Input
First lines (shown under the repo's GPL-3.0 license)
# MobSF Agent Guidelines
MobSF is a security analysis platform. Every code path processes attacker-supplied
input (APKs, ZIPs, IPAs, manifests) from authenticated but potentially malicious
users. Security must be the default, not an afterthought.
---
## Code Quality — Mandatory Before Every Commit
Run lint and fix all errors before finishing any task:
```bash
tox -e lint
```
Never leave a task with a non-zero exit code from this command.
---
## Security Architecture
Centralized security helpers live in **`mobsf/MobSF/security.py`**. When adding new
security checks, prefer adding them there. Some legacy validators still live in
`mobsf/MobSF/utils.py`; use existing helpers where they are already established.
### Available Security Functions
Import only the helpers needed for the change:
```python
from mobsf.MobSF.security import (
# Path safety
is_path_traversal, # .., absolute paths, URL encoding, fullwidth forms; on Windows also ADS, CON/NUL, trailing dot/space
is_safe_path, # Containment check after path construction via realpath()
# Input validation
is_attack_pattern, # Detect shell injection: ;, $(), |, &&, backticks, newlines (returns bool)
cmd_injection_check, # Detect OS command injection characters (raw and URL-encoded)
is_safe_windows_batch_arg, # Reject cmd.exe metacharacters in .bat/.cmd arguments
is_pipe_or_link, # Detect symlinks, junctions, FIFOs, sockets and device files
# Output sanitization
sanitize_filename, # Safe filename for Content-Disposition headers
sanitize_for_logging,# Strip newlines and control chars before logging user input
sanitize_redirect, # Allow only relative paths in redirects
sanitize_svg, # Strip XSS vectors from SVG content (bleach-based)
clean_filename, # Windows-safe filename (unicode normalization)
# Network / SSRF
valid_host, # DNS-resolves host; rejects private/loopback/multicast IPs
safe_request, # SSRF-safe, DNS-pinned outbound request with bounded response
)
```
`bleach` is deprecated upstream (no new features, security fixes only). Do not
expand its use; when replacing `sanitize_svg`, pick a maintained SVG-aware
sanitizer and keep serving SVG with a restrictive `Content-Security-Policy`.
---
## Past Vulnerabilities and Insecure Patterns
Read `.github/SECURITY.md` to understand the full history of security issues in this
codebase. Use it as a guide for what classes of bugs to watch for and what patterns
have been exploited before. When in doubt about whether a pattern is safe, check
whether a similar pattern has appeared in the advisory history.
---
## Incomplete Fix Anti-Pattern
The most common source of security regressions in this codebase is applying a fix to
one code path but not its siblings. Before closing any security fix:
1. Search for all functions or patterns that perform the same operation (e.g., every
place that resolves an icon path, every place that extracts an archive entry).
2. Verify the fix is applied consistently across **all** of them.
3. Check both the APK binary flow and the source-ZIP flow — they are separate code paths
with separate callsites and have diverged in the past.
---
## Input Trust Model
- `request.GET` / `request.POST`: untrusted. Validate with forms or explicit checks;
escape on output.
- File uploads: untrusted. Validate magic bytes, size limits, and extension allowlists.
- Archive entries (`zip`, `tar`, `ar`): untrusted. Check each entry before extraction.
- `AndroidManifest.xml` values: untrusted. Treat as attacker-controlled before using
them in filesystem operations or rendering them.
- `Info.plist` values: untrusted. Apply the same treatment as manifest values.
- `md5` / `hash` URL parameters: semi-trusted only after validation. Always validate
with `is_md5()` before using them in paths.
- Device identifiers: untrusted. Use command-injection checks plus format validation.
---
## Django-Specific Security Features
### Form Validation — The Primary Input Sanitization Layer
Prefer Django forms for new request validation. If a view does not use a form, validate
every `request.GET[...]` or `request.POST[...]` value explicitly before using it.
The project uses a mixin composition pattern. Combine the appropriate mixins rather than
writing ad-hoc validation in view code:
```python
# StaticAnalyzer/forms.py — mixins to compose from
AttackDetect # is_path_traversal + extension allowlist on a 'file' param
APIChecks # MD5 format check on a 'hash' param (API mode)
WebChecks # MD5 format check on an 'md5' param (HTML mode)
AndroidChecks # ChoiceField allowlist for Android scan type
IOSChecks # ChoiceField allowlist for iOS scan type
```
Custom field validators belong in a `clean_<field>()` method that raises
`forms.ValidationError` on rejection — never return a partial result and check it in
the view. `FormUtil.errors_message(form)` produces the standard error envelope to return
to the caller when `form.is_valid()` is False.
**Use `ChoiceField` for any parameter with a finite set of valid values.** This
eliminates an entire class of injection risk at the form layer with no extra code.
Never use `CharField` and then manually compare the value against an allowlist in the
view — let the form do it.
### View Decorators — Apply All Three
Views that handle sensitive operations should use the applicable Django decorators for
authentication, authorization, and method restriction:
```python
@login_required
@permission_required(Permissions.SCAN) # or DELETE, SUPPRESS, etc.
@require_http_methods(['POST']) # or ['GET'] — never omit this
def my_view(request, api=False):
...
```
- `@login_required` blocks unauthenticated access.
- `@permission_required` enforces role-based access beyond authentication.
- `@require_http_methods` rejects wrong HTTP verbs before any logic runs,
preventing CSRF-via-GET and other method-confusion issues.
### Template Auto-Escaping
Django's template engine escapes variables by default. Do **not** use `{% autoescape off %}`
or the `|safe` filter on any value derived from scan data, manifests, or user input.
When rendering user-controlled strings outside of templates (e.g., in a JSON response
built by hand), use `django.utils.html.escape()` explicitly. Template auto-escaping
does not protect JavaScript DOM sinks: never assign scan, task, or user-derived
strings to `innerHTML`; use `textContent` (see `templates/general/tasks.html`).
### ORM — No Raw SQL
Use the Django ORM for all database access. Never use `.raw()` or string-formatted SQL.
When a queryset filter value comes from user input, pass it as a keyword argument
(the ORM parameterizes it automatically):Signals
- Stars
- 22,030
- Forks
- 3,793
- Open issues
- 9
- Last commit (this folder)
- Oct 24, 2026 (4 days ago)
- Last release
- Sep 21, 2026 (1 month ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- GPL-3.0
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Cite this page
AGENTS.md · MobSF/Mobile-Security-Framework-MobSF. Agent Mart. https://agentmart.dev/templates/mobsf-mobile-security-framework-mobsf-agents-md (last updated 2026-10-24)