Skip to content

tanviet12/vbsec / skills/vbs-scan-security

vbs-scan-security

Flagged

Use when scanning code for security vulnerabilities. Use when user says "scan security", "kiểm tra bảo mật", "security audit", "review security", or invokes `/vbs-scan-security`. Auto-delegates to sub-agents for large scans (>20 main-language files OR >30 total OR >14 days). Outputs bilingual reports (vi/en). Optional `--auto-fix` (agentic patch + verify loop) and `--sca` (live CVE lookup via OSV.dev).

FileKindSize
SKILL.mdskill md36.2 KB
VERSIONother6 B
references/chunking-strategy.mdmarkdown7.2 KB
references/data-flow-classification.mdmarkdown9.5 KB
references/dependency-scan.mdmarkdown9.7 KB
references/i18n/en.mdmarkdown8.7 KB
references/i18n/vi.mdmarkdown9.4 KB
references/language-detection.mdmarkdown7.5 KB
references/load-rules.shexecutablescript5.2 KB
references/output-format.mdmarkdown26.1 KB
references/project-context.mdmarkdown2.7 KB
references/sub-agent-prompts.mdmarkdown16.5 KB
references/validate-report.pyexecutablescript8.7 KB
rules/generic/01-hardcoded-secret.mdmarkdown5.4 KB
rules/generic/02-sql-injection.mdmarkdown5.2 KB
rules/generic/03-xss.mdmarkdown4.9 KB
rules/generic/04-idor.mdmarkdown5.7 KB
rules/generic/05-slopsquatting.mdmarkdown6.1 KB
rules/generic/06-brute-force.mdmarkdown6.9 KB
rules/generic/07-mass-assignment.mdmarkdown6.3 KB
rules/generic/08-insecure-deserialization.mdmarkdown6.3 KB
rules/generic/09-ssrf.mdmarkdown6.7 KB
rules/generic/10-path-traversal.mdmarkdown6.3 KB
rules/generic/11-csrf.mdmarkdown7.8 KB
rules/generic/12-broken-access-control.mdmarkdown7.9 KB
rules/generic/13-weak-password-hashing.mdmarkdown5.2 KB
rules/generic/14-jwt-none-algorithm.mdmarkdown5.3 KB
rules/generic/15-cors-misconfig.mdmarkdown5.3 KB
rules/generic/16-unrestricted-file-upload.mdmarkdown5.9 KB
rules/generic/17-verbose-error-debug-mode.mdmarkdown5.8 KB
rules/generic/18-missing-rate-limit.mdmarkdown10.7 KB
rules/generic/19-race-condition.mdmarkdown11.5 KB
rules/generic/20-outdated-dependency.mdmarkdown7.2 KB
rules/generic/21-command-injection.mdmarkdown6.6 KB
rules/generic/22-vulnerable-dependency.mdmarkdown5.3 KB
rules/generic/23-llm-prompt-injection.mdmarkdown9.7 KB
rules/generic/24-excessive-agency.mdmarkdown10.1 KB
rules/generic/25-tenant-isolation.mdmarkdown10.1 KB
rules/generic/26-authz-path-parity.mdmarkdown10.9 KB
rules/generic/27-excessive-data-exposure.mdmarkdown10.4 KB
rules/generic/28-business-state-integrity.mdmarkdown9.5 KB
rules/generic/29-sensitive-data-in-logs.mdmarkdown9.1 KB
rules/generic/30-auth-session-lifecycle.mdmarkdown9.4 KB
rules/generic/31-resource-exhaustion.mdmarkdown9.0 KB
rules/languages/README.mdmarkdown8.5 KB
rules/languages/dart/01-hardcoded-secret.mdmarkdown7.9 KB
rules/languages/dart/03-xss.mdmarkdown5.2 KB
rules/languages/dart/05-slopsquatting.mdmarkdown4.6 KB
rules/languages/dart/10-path-traversal.mdmarkdown6.3 KB
rules/languages/dart/12-broken-access-control.mdmarkdown8.3 KB
rules/languages/dart/17-verbose-error-debug-mode.mdmarkdown6.7 KB
rules/languages/dart/20-outdated-dependency.mdmarkdown4.7 KB
rules/languages/dart/README.mdmarkdown3.7 KB
rules/languages/dotnet/02-sql-injection.mdmarkdown5.7 KB
rules/languages/dotnet/07-mass-assignment.mdmarkdown6.0 KB
rules/languages/dotnet/08-insecure-deserialization.mdmarkdown5.7 KB
rules/languages/dotnet/17-verbose-error-debug-mode.mdmarkdown5.0 KB
rules/languages/dotnet/21-command-injection.mdmarkdown5.3 KB
rules/languages/dotnet/README.mdmarkdown1.7 KB
rules/languages/go/02-sql-injection.mdmarkdown5.2 KB
rules/languages/go/08-insecure-deserialization.mdmarkdown5.0 KB
rules/languages/go/09-ssrf.mdmarkdown5.8 KB
rules/languages/go/17-verbose-error-debug-mode.mdmarkdown6.1 KB
rules/languages/go/21-command-injection.mdmarkdown5.2 KB
rules/languages/go/README.mdmarkdown2.7 KB
rules/languages/php/02-sql-injection.mdmarkdown5.8 KB
rules/languages/php/08-insecure-deserialization.mdmarkdown6.2 KB
rules/languages/php/11-csrf.mdmarkdown6.2 KB
rules/languages/php/17-verbose-error-debug-mode.mdmarkdown6.5 KB
rules/languages/php/21-command-injection.mdmarkdown6.7 KB
rules/languages/php/README.mdmarkdown2.9 KB
rules/languages/python/02-sql-injection.mdmarkdown7.2 KB
rules/languages/python/07-mass-assignment.mdmarkdown7.3 KB
rules/languages/python/08-insecure-deserialization.mdmarkdown7.3 KB
rules/languages/python/09-ssrf.mdmarkdown7.5 KB
rules/languages/python/11-csrf.mdmarkdown7.6 KB
rules/languages/python/14-jwt-none-algorithm.mdmarkdown7.5 KB
rules/languages/python/15-cors-misconfig.mdmarkdown8.0 KB
rules/languages/python/17-verbose-error-debug-mode.mdmarkdown8.4 KB
rules/languages/python/21-command-injection.mdmarkdown8.5 KB
rules/languages/python/README.mdmarkdown3.4 KB
rules/languages/typescript/02-sql-injection.mdmarkdown7.5 KB
rules/languages/typescript/03-xss.mdmarkdown6.7 KB
rules/languages/typescript/07-mass-assignment.mdmarkdown7.4 KB
rules/languages/typescript/08-insecure-deserialization.mdmarkdown7.0 KB
rules/languages/typescript/09-ssrf.mdmarkdown7.5 KB
rules/languages/typescript/11-csrf.mdmarkdown7.3 KB
rules/languages/typescript/14-jwt-none-algorithm.mdmarkdown7.0 KB
rules/languages/typescript/15-cors-misconfig.mdmarkdown7.2 KB
rules/languages/typescript/17-verbose-error-debug-mode.mdmarkdown7.2 KB
rules/languages/typescript/21-command-injection.mdmarkdown6.7 KB
rules/languages/typescript/README.mdmarkdown3.3 KB
workflows/auto-fix.mdmarkdown18.9 KB
workflows/large-review.mdmarkdown10.5 KB
workflows/small-review.mdmarkdown10.1 KB

rules/languages/dart/12-broken-access-control.md

View on GitHub
---
id: BROKEN-ACCESS-CONTROL
severity_max: CRITICAL
applies_to: dart
overrides: generic/12-broken-access-control.md
---

# Broken Access Control — Dart / Flutter (phiên trên máy, backup, deep link)

> Override cho `rules/generic/12-broken-access-control.md` khi `primary_language: dart`. Repo có backend Dart (`shelf`, `dart_frog`, `serverpod`, `alfred`) → với thư mục server, áp nguyên logic generic (route thiếu auth, thiếu kiểm ownership).

## Intent (Flutter-specific)

App client không tự phân quyền dữ liệu: server lọc theo token. "Thiếu kiểm quyền" ở app thường là **kết thúc phiên không sạch** hoặc **cửa vào app mở cho app khác**:

1. **Xoá phiên thiếu RAM**: đăng xuất / 401 chỉ xoá token trong storage rồi về màn đăng nhập; state toàn cục (Provider `ChangeNotifier`, Riverpod, Bloc/Cubit, GetX, singleton) vẫn giữ hồ sơ, danh sách giao dịch, tài khoản của người trước. Máy dùng chung (quầy, cửa hàng): người sau đăng nhập thấy / dùng nhầm dữ liệu người trước.
2. **401 chỉ nhận ở một số verb**: lớp HTTP đổi 401 thành lỗi "hết phiên" ở `get()` nhưng `post()` chỉ ném chuỗi thông báo. Token bị thu hồi (đổi mật khẩu, chủ tài khoản thu quyền) → chính nút Đăng xuất (POST) lỗi → app **kẹt phiên**, dữ liệu vẫn hiện.
3. **Sao lưu mang dữ liệu phiên đi**: Android `android:allowBackup` mặc định `true`; không tắt và không có `dataExtractionRules` / `fullBackupContent` loại `sharedpref`, `file`, `database` → token, cache giao dịch theo bản sao lưu sang máy khác.
4. **Deep link / component exported không dùng**: `<intent-filter>` VIEW + BROWSABLE với scheme riêng, `<activity|service|receiver android:exported="true">` không cần thiết. Flutter mặc định chuyển deep link cho router (`flutter_deeplinking_enabled`), nên app / trang web khác mở được thẳng màn nội bộ (`/transaction/<id>`, `/settings`, màn debug) dù code không có tính năng deep link nào.

## Khi nào HIGH

- Deep link mở được route **thực hiện hành động** không cần xác nhận (chuyển tiền, đổi cài đặt bảo mật, đăng xuất máy khác), hoặc route debug lộ token / đổi API base URL.
- Đăng xuất không xoá cache **trên đĩa** (Hive / sqflite / file) chứa dữ liệu giao dịch của người trước, người sau đăng nhập đọc được.
- `allowBackup` bật (hoặc không khai: mặc định `true`) trong khi token nằm ở `SharedPreferences` / file thường. Tạo finding riêng ở `AndroidManifest.xml`, ngoài finding HARDCODED-SECRET ở chỗ lưu token: hai chỗ sửa khác nhau.

## Khi nào MEDIUM

- Pattern 1: hàm đăng xuất / nhánh 401 không xoá store trong bộ nhớ (chỉ RAM, không ra khỏi tiến trình).
- Pattern 2: lớp HTTP xử lý 401 không đồng nhất giữa các verb, hoặc màn đăng xuất bắt buộc request thành công mới xoá phiên.
- Pattern 3: `allowBackup` không tắt, dữ liệu nhạy cảm (cache giao dịch, hồ sơ) nằm trong sandbox dạng thường; token đã ở Keystore.
- Deep link exported mở được route chỉ-xem (dữ liệu vẫn cần token).

## Khi nào LOW / KHÔNG tạo finding

- Intent-filter custom scheme **có dùng** (code xử lý link, route kiểm định dạng tham số): không finding cho cửa vào; xét tham số ở rule PATH-TRAVERSAL / XSS.
- Chỉ token trong `flutter_secure_storage` (Keystore, khoá không xuất được) mà `allowBackup` bật: hardening note.
- Coi **mọi** 401 là hết phiên kể cả request đăng nhập: không phải lỗ hổng (chỉ mất câu báo "sai mật khẩu" vì nhiều API trả 401 cho cả hai). Khi gợi ý sửa pattern 2, chỉ coi 401 là hết phiên **khi request có gửi token**.
- App không có khoá đăng nhập sau N lần sai, không có PIN / sinh trắc: không phải finding (chống dò là việc server). Thiếu lớp che app switcher (`AppLifecycleState.inactive` / `FLAG_SECURE`) cho app hiện số dư: **hardening note**.

## Cách reasoning

1. Tìm mọi điểm kết thúc phiên: `logout`, `signOut`, nhánh `401` / `Unauthorized` / `SessionExpired`, `onResume` kiểm phiên, interceptor `onError` của Dio. Liệt kê store toàn cục (`ChangeNotifier`, `StateNotifier`, `Cubit`, `GetxController`, singleton có field dữ liệu người dùng). Mỗi nhánh có gọi một hàm xoá chung (`clearSession`) xoá token + mọi store + header HTTP + cache đĩa không?
2. Đọc lớp HTTP (`http.Client` wrapper, Dio interceptor): 401 được nhận diện ở verb nào? `post` / `put` / `delete` có cùng nhánh không? Đăng xuất gặp 401 có xoá cục bộ không?
3. Đọc `android/app/src/main/AndroidManifest.xml`: `allowBackup`, `fullBackupContent`, `dataExtractionRules` (đọc file XML được trỏ tới), mọi `exported="true"`, mọi `<intent-filter>` có `android.intent.action.VIEW`. iOS: `CFBundleURLTypes`, `com.apple.developer.associated-domains` trong entitlements.
4. Đối chiếu cửa vào với code: có `app_links` / `uni_links` / `getInitialLink` / route nào dùng scheme đó không? Router có `redirect` chặn khi chưa đăng nhập, route debug có bọc `kDebugMode` không?

## Search patterns (gợi ý — dùng Grep tool)

```
(logout|signOut|clearSession|onUnauthorized)\s*\(
(==|case)\s*['"]?401|statusCode\s*==\s*401|UnauthorizedException|SessionExpired
(prefs|storage|storageHelper)\.(clear|remove|delete)\s*\(
extends\s+(ChangeNotifier|StateNotifier|Cubit|Bloc|GetxController)
android:allowBackup|android:fullBackupContent|android:dataExtractionRules
android:exported\s*=\s*"true"
android\.intent\.action\.VIEW|android:scheme=
flutter_deeplinking_enabled
CFBundleURLSchemes|associated-domains
```

## Examples

### MEDIUM — flag

```dart
// 401 chỉ xoá storage; UserModel / TransactionModel vẫn giữ dữ liệu người trước
} catch (e) {
  if (e == '401') {
    await storage.clear();
    context.go('/login');
  }
}
```

```dart
// get() nhận 401, post() thì không → token bị thu hồi thì Đăng xuất (POST) kẹt
Future get(String path) async { ... if (res.statusCode == 401) throw SessionExpired(); }
Future post(String path, Map body) async { ... if (res.statusCode != 200) throw json['message']; }
```

```xml
<!-- Deep link không ai dùng, router vẫn nhận: app khác mở thẳng màn nội bộ -->
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="shopapp" />
</intent-filter>
```

### NOT flag

```dart
// Một hàm xoá phiên, gọi ở đăng xuất và mọi nhánh 401
Future<void> clearSession() async {
  _token = null; _profile = null; _accounts = [];
  http.setToken('');
  await secureStorage.delete(key: 'access_token');
  notifyListeners();
}
// Lớp HTTP: có token mà bị 401 → hết phiên; đăng nhập (chưa có token) giữ câu báo của server
if (hasToken && res.statusCode == 401) throw SessionExpired();
```

## Fix recommendation

1. Gom về **một** `clearSession()` xoá token (RAM + Keychain), mọi store, header HTTP, cache đĩa, file tạm; gọi ở đăng xuất, 401 lúc mở app, 401 lúc quay lại app, 401 trong request nền. Viết test: sau `clearSession()` mọi getter rỗng.
2. Lớp HTTP ném **một** lỗi hết phiên cho mọi verb khi request có token mà nhận 401. Đăng xuất gặp lỗi đó → xoá cục bộ, về màn đăng nhập (server đã không còn nhận token).
3. `AndroidManifest.xml`: `android:allowBackup="false"`, `android:fullBackupContent="false"`, `android:dataExtractionRules="@xml/data_extraction_rules"` loại `root`, `file`, `database`, `sharedpref`, `external` ở cả `<cloud-backup>` và `<device-transfer>`.
4. Bỏ intent-filter / URL type không dùng; nếu cần deep link, khai đúng host + path, kiểm tham số theo định dạng, route nhạy cảm yêu cầu xác nhận.

## Cross-references

- `01-hardcoded-secret` (Dart): token lưu sai chỗ.
- `10-path-traversal` (Dart): tham số deep link / push ghép vào đường dẫn router.
- `17-verbose-error-debug-mode` (Dart): route debug không bọc `kDebugMode`.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall