Skip to content
Back to skills

Magento2 Security Scan

ASecurity

Use when auditing Magento 2 security: XSS, CSRF, form security, dependency and outdated package checks, PCI compliance, or a security review before deploy. Keywords security audit, XSS, CSRF.

  • 5 stars
  • 0 votes
  • 2 copies
  • 3 views
  • Added September 19, 2026
ai-agentsjavascriptgojavaphpbashsqlnodecode-reviewgitapi

Works with

  • api

Security analysis

A96/100
  • mediumUses curl or wget to download content

Pro shows the line behind each finding and how to fix it

Scanned November 15, 2026

npx -y skills add ddtcorex/maestro-skills --skill magento2-security-scan --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Magento2 Security Scan?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Magento2 Security Scan
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ddtcorex-magento2-security-scan/badge)](https://www.skillsdirectory.com/skills/ddtcorex-magento2-security-scan)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: magento2-security-scan
description: "Use when auditing Magento 2 security: XSS, CSRF, form security, dependency and outdated package checks, PCI compliance, or a security review before deploy. Keywords security audit, XSS, CSRF."
compatibility: claude, codex, opencode, copilot, dsh
depends: [magento2-dev-core]
metadata:
  audience: developers
  workflow: magento
---

# Magento 2 Security Scanner

## When to use

Load this skill to scan Magento 2 code for vulnerabilities and compliance issues; it is DEPENDENT on magento2-dev-core for security patterns.

- "run a security audit", "find vulnerabilities", "check for XSS", "check CSRF protection", "validate form security"
- "run a dependency audit", "check for outdated packages", "run a PCI compliance check"
- "do a security review before deploy"

This skill performs security scanning for vulnerabilities, misconfigurations, and compliance issues.

## Govard-Native Audit Coverage

`govard audit run` executes PHPCS and PHPStan through Govard's pinned lint
toolchain image, it covers coding-standard and static-analysis findings only.
As of Govard v1.64.0 no `security` audit check exists:
`govard audit run --checks security` fails with "audit check ... is not
implemented". The lint run does include a pub/media PHP guard since v1.64.0, every PHP file
under `pub/media` is flagged (`M2-LINT-MEDIA`), so a lint pass also covers that specific
file-drop attack surface, but it is still not a vulnerability scan. Run this skill's manual
checklist yourself and treat `govard audit run --checks lint` as the shared lint gate. Never
present a lint-only pass as a security verdict.

## Related Skills

**REQUIRED BACKGROUND:** Load `magento2-dev-core` first, this skill scans for violations of the security patterns it defines (escaping, discouraged functions, ObjectManager misuse), and its patterns are what you fix findings with.

Part of the QA trio with `magento2-linter` (style/static analysis) and `magento2-performance-audit` (runtime/infrastructure). Re-check API/resolver-specific findings against `magento2-backend-dev`.

## Vulnerability Categories

### 1. Injection Vulnerabilities

| Type | Pattern | Severity | Code |
|------|---------|----------|------|
| SQL Injection | Direct SQL with user input | Critical | M2-SEC-001 |
| XSS (Reflected) | Unescaped user input in output | High | M2-SEC-003 |
| XSS (Stored) | Unescaped database content | Critical | M2-SEC-002 |
| Command Injection | System command execution with user input | Critical | M2-SEC-004 |

Full scale and code catalogue: `magento2-dev-core/references/severity-and-codes.md`.

### 2. Authentication & Authorization

| Check | Command |
|-------|---------|
| Admin path changed | Check env.php for custom admin path |
| 2FA enabled | Check admin/twofactor module |
| Password hashing | Verify EncryptorInterface usage |
| Session security | Check cookie configuration |

### 3. Data Exposure

```bash
# Check for exposed sensitive files
curl -I https://store.test/app/etc/env.php
curl -I https://store.test/var/log/system.log
curl -I https://store.test/.git/config

# Expected: All should return 403 or 404
```

### 4. CSP Configuration

```bash
# Magento has no config:get; config:show resolves the full precedence chain.
govard sh -c "bin/magento config:show csp/mode/storefront/report_only"
# (cms/wysiwyg/use_static_urls_in_catalog is a real path but a catalog setting, not CSP)
```

## Scanner Commands

### PHP Security Checker

Magento ships no scanner binary: `magento/security-package` is the metapackage
for the 2FA, reCAPTCHA and admin security modules, not a patch package, and the
official Security Scan is a hosted service you register a public URL with from
your Adobe Commerce account (account.magento.com), not from the store admin. Locally, `composer audit` (below) plus the
Adobe security bulletin for your exact version is what you can run.

### Dependency Audit

```bash
# Check for known vulnerabilities
govard sh -c "composer audit --no-interaction"

# Machine-readable CVE list (composer outdated --format=json returns an object
# keyed `installed`/`locked` with no advisories, so it cannot answer this)
govard sh -c "composer audit --format=json | jq -r '.advisories | keys[]'"
```

### File Permission Check

```bash
# Check Magento file permissions
find var/ pub/static pub/media -type f -not -perm 0644 -ls
find var/ pub/static pub/media -type d -not -perm 0755 -ls
find app/etc -type f -not -perm 0640 -ls
```

## Scoping

The "Quick Security Scan" greps default to a full module path
(`app/code/Vendor/Module`). Given an explicit file list instead, loop over it
the same way:

```bash
for f in app/code/Vendor/Module/Controller/Index/Index.php app/code/Vendor/Module/Model/Foo.php; do
  grep -Hn "\$_GET\|\$_POST\|\$_REQUEST\|ObjectManager::getInstance\|eval(" "$f"
done
```

`magento2-code-review` derives this file list from a git diff or an MR fetch
and calls this skill with it directly, the git/glab mechanics themselves
live there, not here.

### Environment-level checks: scope boundary

Authentication & Authorization, Data Exposure, and CSP Configuration
(sections 2-4 above) are not file-list-scoped at all, they check the
running environment (`env.php`, a live URL, `bin/magento config:show`), not
specific files. They cannot run against a PR/MR diff or remote fetch (no
checked-out environment to query there) and, even at project/module scope,
run once per audit rather than once per file. `magento2-code-review`
states explicitly in its Coverage note whether these ran (project/module/
theme scope, live environment available) or were skipped (PR/MR scope, or
no environment access this session), this is never left for whoever's
running the review to decide silently.

## XSS Prevention Checklist

- [ ] All output escaped with `$escaper`
- [ ] `escapeHtml` for HTML content
- [ ] `escapeHtmlAttr` for attributes
- [ ] `escapeJs` for JavaScript strings
- [ ] `escapeUrl` for URLs
- [ ] Form keys in all POST forms
- [ ] No direct `$_GET`, `$_POST`, `$_REQUEST` usage

## CSRF Protection

### Verified Patterns

```php
// Form with form key
<form action="<?= $escaper->escapeUrl($action) ?>" method="post">
    <?= $block->getBlockHtml('formkey') ?>
</form>

// AJAX with form key. Inside an AMD module declare the dependencies
// (define(['jquery', 'mage/cookies'], function ($) {...})); there is no global
// $ in Magento's module scope, and 'mage/cookies' provides $.mage.cookies.
// Alternatively pass the form key from the template into the component config.
$.ajax({
    url: url,
    type: 'POST',
    data: {
        form_key: $.mage.cookies.get('form_key'),
        ...data
    }
});
```

### Verify Admin Protection

```bash
# Check if admin form key validation is active
govard sh -c "bin/magento config:show admin/security/use_form_key"
# Expected: 1
```

## Rate Limiting

Magento has no built-in rate-limit switch (`web/secure/open_restriction_enabled`
is not a real config path, so setting it writes a dead row). Rate limiting is an
edge control: put it in nginx, the WAF or the CDN in front of the store, and
verify it there.

## Security Headers

Check in nginx/Apache config or .htaccess:

```
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
```

## PCI-DSS 4.0 Checklist (E-commerce)

Since 31 March 2025 the v4.0 future-dated requirements (6.4.3 and 11.6.1) apply to payment pages:

- [ ] `unsafe-eval` CSP disabled
- [ ] `unsafe-inline` CSP disabled
- [ ] No inline scripts in payment forms
- [ ] TLS 1.2+ enforced

## Quick Security Scan

> **Quick check:** grep -R "\$_GET|\$_POST|ObjectManager::getInstance" --include="*.phtml" over the changed templates. Address high-risk hits first.

Run this for a rapid security assessment. Run one grep per pattern and exclude ORM-layer hits (Collection/Repository/ResourceModel class files) when judging results:

```bash
# 1. Check for SQL in code
grep -r "execute\|fetch\|fetchAll\|select\|insert\|update\|delete" \
    app/code/Vendor/Module --include="*.php" | \
    grep -v "Collection\|Repository\|ResourceModel"

# 2. Check for superglobals
grep -r "\$_GET\|\$_POST\|\$_REQUEST" \
    app/code/Vendor/Module --include="*.php"

# 3. Check for ObjectManager
grep -r "ObjectManager::getInstance" \
    app/code/Vendor/Module --include="*.php"

# 4. Check for code evaluation functions
grep -r "eval" app/code/Vendor/Module --include="*.php"
```

## Findings report

Every confirmed security finding goes into one report. Write every finding to `findings.json` in the shared schema (`magento2-dev-core/references/findings-schema.md`): `tool: "magento2-security-scan"`, the four severities only, a code from `severity-and-codes.md` (or `code: null` with the tool's rule id in `rule`), and `summary` counts that match the findings. Then render it:

```bash
node <skills>/magento2-dev-core/scripts/report/render.mjs render --layout findings --audience dev --data findings.json --out <report-dir>
```

The engine writes `report.md`, `report.html` and `report.body.html` with the shared theme and report contract, so a brand overlay works on this report the same way as on a performance audit. It refuses mismatched counts and unknown codes with exit 1; fix the data, never the rendered file.

## Compliance Report

```markdown
# Security Audit Report

## Injection Vulnerabilities
- [ ] No SQL injection vectors
- [ ] No XSS vulnerabilities
- [ ] No command injection

## Authentication
- [ ] Admin path changed from /admin
- [ ] 2FA enabled
- [ ] Strong password policy

## Data Protection
- [ ] Sensitive files not exposed
- [ ] File permissions correct
- [ ] CSP configured

## PCI-DSS (if applicable)
- [ ] CSP no unsafe-eval on checkout
- [ ] No inline scripts in payment forms
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.