Secure

From grafana/grafana-pathfinder-app · View interactive version

Secure is an AI agent skill from the GitHub repository grafana/grafana-pathfinder-app. Security audit of frontend code (F1-F6 from `.cursor/rules/frontend-security.mdc`), the Go backend, the MCP HTTP transport, and dependencies (`npm audit`, Go advisories). Reports findings with concrete remediation per rule and never edits source. Use for a security audit or a change touching auth, t

How to use this skill

Skill file

Security audit

Skillifies the /secure slash-command label in CLAUDE.md with a real workflow. Audits the current working tree or a PR diff against the repo's canonical security rules, the backend's allowlist contracts, the MCP transport mitigations, and dependency advisories. Emits a severity-ordered findings list with concrete remediation. Never touches source — the security analyst applies fixes, not the skill.

This skill complements:

Hard constraints

These constraints are absolute and override any other instructions:

  1. Never edit source files. This skill is report-only. The reviewer applies fixes.
  2. [security] is reserved for clear violations — F1-F6 hits, backend allowlist bypasses, token leaks, or known CVEs. Speculative or theoretical risks use [suggestion] or [question] from the standard prefix table in docs/design/PR_REVIEW.md. False positives erode trust; prefer false negatives.
  3. Ground every F1-F6 finding in .cursor/rules/frontend-security.mdc. Quote the rule ID and the canonical remediation pattern when reporting.
  4. For backend findings, quote the offending line with file:line reference and the canonical pattern (e.g., isAllowedInteractiveLearningHost, auth.AccessTokenHeader, validIDToken).
  5. Sentence case for findings and remediation text.
  6. Reads only. No gh pr edit, no git commit, no file writes.

Workflow

Phase 0 — Scope

Determine the target:

```

base=$(gh pr view --json baseRefName -q .baseRefName 2>/dev/null || echo main)

git diff --name-only $base...HEAD

```

Capture the list of files to audit; bucket by type:

Phase 1 — Frontend audit (F1-F6)

For each .ts / .tsx / .js / .jsx file in scope, read the changed hunks and apply the detection table from .cursor/rules/frontend-security.mdc. Run or inspect ESLint when feasible; direct F5 DOM sinks are owned by no-restricted-syntax in eslint.config.mjs.

| ID | What to detect | Severity |

| --- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- |

| F1 | Untrusted / dynamic SVG passed to dangerouslySetInnerHTML without DOMPurify.sanitize(svg, { USE_PROFILES: { svg: true } }) | Critical |

| F2 | dangerouslySetInnerHTML used where {} auto-escape would do | High |

| F3 | URL built via string concat (apiBase + '/users?id=' + userId) instead of new URL() + URL.searchParams.set() | High |

| F4 | dangerouslySetInnerHTML without textUtil.sanitize() (or sanitizeDocumentationHTML() from src/security/) | Critical |

| F5 | Security lint failure, new no-restricted-syntax bypass, or equivalent raw DOM/script sink not covered by lint | Critical |

| F6 | URL passed to href / src without textUtil.sanitizeUrl() or a scheme-allowlist check (parseUrlSafely, isAllowedContentUrl) | High |

Detection rules:

Report each finding with:

Example:

[security][F5] src/components/Foo.tsx:42 — Direct DOM sink bypass.

Risk: XSS — user-controlled content bypasses React's auto-escape.
Remediation: use React rendering, `textContent`, or a sanitized rendering helper.
See F5 in `.cursor/rules/frontend-security.mdc`.

Phase 2 — Backend audit (`pkg/**`)

For each *.go file in pkg/ that the diff touches, check for:

B1. Allowlist bypass (severity: Critical)

B2. Forwarded identity without validation (severity: High)

B3. Hardcoded secrets (severity: Critical)

B4. Unbounded payload reads (severity: Medium)

B5. Path-traversal in resource handlers (severity: High)

Quote each finding with file:line and the canonical pattern reference.

Phase 3 — MCP transport audit

If the diff touches src/cli/mcp/**, verify:

M1. New HTTP transport code includes the existing safety caps (severity: High)

Reference: src/cli/mcp/transports/http.ts. If a new transport surface lacks these, flag.

M2. Tool inputs validated via Zod (severity: High)

M3. User content quoted, not interpolated (severity: High)

M4. State-mutating tools require confirmation (severity: High)

Phase 4 — Dependency audit

Always run:

  1. npm audit for production deps:

```

npm audit --omit=dev --json 2>&1

```

  1. Go modules:

```

cd pkg && go list -m -json -u all 2>&1 | head -40

```

  1. Dev-only deps (npm audit without --omit=dev) are informational. Report total counts but do not flag as blocking.

Phase 5 — Report

Group findings by severity. Print in this order:

## Security audit — <date>

Target: <scope description, e.g., "PR diff against main, 12 files">

### Critical (N)

- [security][F5] src/components/Foo.tsx:42 — Direct DOM sink bypass. ...
- [security][B3] pkg/plugin/internal.go:18 — Hardcoded bearer token. ...

### High (N)

- ...

### Medium (N)

- ...

### Low / Informational (N)

- ...

### Disposition

<one line: clean | minor | blocking>

<if blocking: "Do not merge until critical / high findings are addressed.">

Disposition rules:

Print a per-finding summary table at the end:

| ID  | Count |
| --- | ----- |
| F1  | 0     |
| F2  | 1     |
| ... | ...   |

This helps the reviewer scan the surface quickly.

Reuses

Integration

When to exit cleanly without making changes

Context window management

Total context per run: under 30k tokens for a typical PR. Full-tree mode (--full) is larger but bounded by the audited file count.

Expected invocation patterns

What this skill does NOT do

Worked example output (clean run)

## Security audit — 2026-05-11

Target: PR diff against main, 4 files touched

### Critical (0)

(none)

### High (0)

(none)

### Medium (0)

(none)

### Low / Informational (2)

- [info] npm audit: 12 moderate, 1 low vulnerabilities. None in production deps.
- [info] go list: 3 modules with available updates; none with known CVEs.

### Disposition

clean

Worked example output (with findings)

## Security audit — 2026-05-11

Target: PR diff against main, 7 files touched

### Critical (1)

[security][F4] src/components/docs-panel/docs-panel.tsx:218 — `dangerouslySetInnerHTML` without sanitization.

  <div dangerouslySetInnerHTML={{ __html: rawGuideContent }} />

Risk: XSS — `rawGuideContent` is fetched from external CDN and not sanitized.
Remediation: wrap with `sanitizeDocumentationHTML(rawGuideContent)` from `src/security/html-sanitizer.ts`.
See F4 in `.cursor/rules/frontend-security.mdc`.

### High (1)

[security][B1] pkg/plugin/sessions.go:34 — External URL request bypasses host allowlist.

  resp, err := http.Get(req.URL.String())

Risk: allows arbitrary external requests from the plugin backend.
Remediation: route through `isAllowedInteractiveLearningHost(req.URL.String())` (see `pkg/publiccontent/recommendations.go:144-154`).

### Medium (0)

(none)

### Low / Informational (1)

- [info] npm audit: 27 vulnerabilities (1 low, 12 moderate, 8 high, 6 critical). High / critical are in dev deps only.

### Disposition

blocking — do not merge until F4 and B1 are addressed.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.