Skip to content

tanviet12/vbsec / skills/codex/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`. For large scans (>20 main-language files OR >30 total OR >14 days) processes chunks sequentially. Outputs bilingual reports (vi/en). Optional `--auto-fix` (agentic patch + verify loop) and `--sca` (live CVE lookup via OSV.dev).

FileKindSize
SKILL.mdskill md28.8 KB
VERSIONother6 B
agents/openai.yamlconfig313 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-sequential.mdmarkdown14.9 KB
workflows/small-review.mdmarkdown10.1 KB

rules/languages/dotnet/07-mass-assignment.md

View on GitHub
---
id: MASS-ASSIGNMENT
severity_max: CRITICAL
applies_to: dotnet
overrides: generic/07-mass-assignment.md
---

# Mass Assignment — .NET 10 / ASP.NET Core Specialization

> Override cho rule chung `rules/generic/07-mass-assignment.md`. Áp dụng khi `primary_language: dotnet`.

## Intent (.NET-specific)

ASP.NET Core model binding tự động map JSON/form/query vào action parameter. Nếu controller hoặc Minimal API nhận trực tiếp EF entity/domain model (`User`, `Account`, `Order`) rồi gọi `Update`, `Entry(...).State = Modified`, `SetValues`, hoặc save entity đó, attacker có thể gửi thêm field nhạy cảm như `IsAdmin`, `Role`, `Balance`, `TenantId`, `EmailConfirmed`, `Permissions` để leo quyền hoặc sửa dữ liệu ngoài ý muốn.

## Khi nào CRITICAL

- Action/endpoint nhận entity model trực tiếp từ `[FromBody]` hoặc parameter Minimal API: `User inputUser`.
- `DbContext.Update(input)`, `_db.Entry(input).State = EntityState.Modified`, `CurrentValues.SetValues(input)` với input bind từ request.
- `TryUpdateModelAsync(entity)` không có include-list field an toàn.
- DTO có field nhạy cảm (`IsAdmin`, `Role`, `TenantId`, `Balance`) dùng cho user-facing endpoint.
- AutoMapper map toàn bộ DTO/request vào entity mà không ignore sensitive fields.

## Khi nào HIGH (giảm cấp)

- Entity không có field nhạy cảm và endpoint chỉ update public profile fields.
- Có `[Bind("Name,Email")]` include-list rõ ràng hoặc DTO riêng chỉ chứa field cho phép.
- Endpoint admin-only rõ ràng và đổi field nhạy cảm là mục đích chính.
- Field nhạy cảm bị server override sau bind (`entity.Role = "User"`) trước save, nhưng vẫn đọc kỹ thứ tự assignment.

## Cách reasoning

1. Grep action/minimal API nhận model từ request: `[FromBody] User`, `MapPost(... User user ...)`, `TryUpdateModelAsync`, `SetValues`.
2. Read entity class để xác định field nhạy cảm: role, admin, tenant, owner, balance, permissions, status, verified.
3. Trace source:
   - MVC action parameter / Minimal API parameter / `Request.ReadFromJsonAsync<T>()` → L1.
   - DTO internal từ service khác → L3/L4 tùy context.
4. Verify mitigation:
   - DTO/record input riêng không chứa field nhạy cảm.
   - Manual mapping allowlist.
   - `[Bind]` include-list, not exclude-list.
   - AutoMapper profile ignore sensitive members.
5. Flag khi L1 object có thể set field ngoài allowlist trước khi save.

## Search patterns

```
# MVC / Minimal API binds entity-ish names
\[FromBody\]\s*(User|Account|Order|Customer|Member|Profile)\b
Map(Post|Put|Patch)\s*\([^)]*,\s*(async\s*)?\([^)]*\b(User|Account|Order|Customer)\s+\w+
ReadFromJsonAsync\s*<\s*(User|Account|Order|Customer)

# EF update whole object
\.Update\s*\(\s*\w+\s*\)
\.Entry\s*\([^)]+\)\.State\s*=\s*EntityState\.Modified
CurrentValues\.SetValues\s*\(
TryUpdateModelAsync\s*\(

# AutoMapper / mapper direct request to entity
\.Map\s*<\s*(User|Account|Order|Customer)\s*>\s*\(
mapper\.Map\s*\([^,]+,\s*\w+\s*\)

# Sensitive fields
\b(IsAdmin|IsSuperAdmin|Role|Roles|Permissions|TenantId|OwnerId|Balance|CreditLimit|EmailConfirmed|Status)\b
```

## Examples

### CRITICAL — flag

```csharp
// Minimal API bind trực tiếp entity
app.MapPut("/users/{id}", async (int id, User inputUser, AppDbContext db) =>
{
    inputUser.Id = id;
    db.Users.Update(inputUser);
    await db.SaveChangesAsync();
});
// Attacker body: {"name":"x","isAdmin":true,"role":"Admin"}
```

```csharp
// MVC + EntityState.Modified
[HttpPut("{id}")]
public async Task<IActionResult> Put(int id, [FromBody] User user)
{
    user.Id = id;
    _db.Entry(user).State = EntityState.Modified;
    await _db.SaveChangesAsync();
    return Ok();
}
```

```csharp
// SetValues copies all matching properties
var user = await _db.Users.FindAsync(id);
var input = await Request.ReadFromJsonAsync<User>();
_db.Entry(user).CurrentValues.SetValues(input);
await _db.SaveChangesAsync();
```

```csharp
// DTO still unsafe because it exposes sensitive fields
public record UpdateUserRequest(string Name, string Role, bool IsAdmin);

[HttpPatch("{id}")]
public async Task<IActionResult> Patch(int id, UpdateUserRequest req)
{
    _mapper.Map(req, await _db.Users.FindAsync(id));
    await _db.SaveChangesAsync();
    return Ok();
}
```

### NOT critical — không flag

```csharp
// DTO only has allowed fields
public record UpdateProfileRequest(string DisplayName, string Bio);

app.MapPut("/me", async (UpdateProfileRequest req, ClaimsPrincipal user, AppDbContext db) =>
{
    var me = await db.Users.SingleAsync(u => u.Id == user.UserId());
    me.DisplayName = req.DisplayName;
    me.Bio = req.Bio;
    await db.SaveChangesAsync();
});
```

```csharp
// Bind include-list
public async Task<IActionResult> Edit(
    [Bind("DisplayName,Bio,TimeZone")] UserProfile input)
{
    ...
}
```

```csharp
// Admin endpoint explicitly changes role and checks authorization
[Authorize(Roles = "Admin")]
[HttpPatch("/admin/users/{id}/role")]
public async Task<IActionResult> ChangeRole(int id, ChangeRoleRequest req)
{
    var user = await _db.Users.FindAsync(id);
    user.Role = req.Role;
    await _db.SaveChangesAsync();
    return Ok();
}
```

## Fix recommendation

1. Không nhận EF entity/domain model trực tiếp trong public action. Tạo DTO/record riêng cho từng use case.
2. Manual map field được phép; tránh `Update(entity)` với object bind từ request.
3. Dùng `[Bind("Allowed,Fields")]` nếu bắt buộc model binding MVC, nhưng DTO vẫn rõ hơn.
4. AutoMapper profile phải `Ignore()` field nhạy cảm (`Role`, `IsAdmin`, `TenantId`, `Balance`).
5. Field ownership/tenant/role phải lấy từ auth context hoặc server-side policy, không từ request body.

## Cross-references

- `12-broken-access-control`: mass assignment thường biến thành privilege escalation.
- `04-idor`: attacker đổi `OwnerId`/`TenantId` để chạm dữ liệu người khác.
- `02-sql-injection`: cùng nguồn L1 từ ASP.NET Core route/body binding.
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: 471kUpdated 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: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated 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