Defra security and PII handling — never hard-code secrets, never log PII, refuse unsafe template patterns, and redact known UK PII (NI numbers, NHS numbers, postcodes, DoB combinations) before any output leaves the service. Use when the agent is editing code that handles user data, writing log lines, configuring templates, or wiring credentials.
Ships in defra-shared. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Defra services handle data from members of the public. The agent treats every string that may have come from a user as untrusted, every credential as something that must never reach a repository, and every log line as something a third party may eventually read.
.env file that is git-ignored.secret-scan runs on every Write / Edit and blocks the change when a known secret pattern matches. It currently flags AWS access key ids, PEM private-key blocks, GitHub tokens (ghp_… / gho_… / ghs_… / ghu_… / ghr_…), Slack tokens (xox[abpr]-…), Anthropic API keys (sk-ant-…), OpenAI API keys (sk-proj-… / sk-svcacct-… / sk-admin-…), Stripe live/test keys, Google API keys (AIza…), JWTs (eyJ….eyJ….…), and any <keyword>… = "<value>" assignment whose keyword is apiKey / secret / password / passwd / token / bearer and whose value is a quoted alphanumeric or base64 string of ≥ 16 characters. The provisional full-scan tool is gitleaks.The agent treats the following as PII that must never appear in logs, error messages, telemetry, analytics events, or any artefact that leaves the service boundary:
AB123456C).nnn nnn nnnn).Log structured fields by identifier (e.g. userId, caseRef), not by the underlying PII. Use a redactor in the logging library (pino redact paths, Serilog Destructurer, structlog processor) to belt-and-brace any field that ends up in a log line.
The companion hook pii-scan runs on every Write / Edit and warns when a PII pattern is detected in a changed file. It is async (warning only) so it does not block legitimate fixture data.
For Nunjucks (frontend), Razor (.NET), and Jinja2 (Python):
autoescape: false is forbidden in production templates.| safe filter (Nunjucks / Jinja2) and Html.Raw (.NET) are permitted only on server-rendered, pre-sanitised content. Never on user-supplied data.<script> or <style> blocks; no style= attributes; no javascript: URLs.crumb in Hapi; antiforgery in ASP.NET Core; csrf_token() in FastAPI / Jinja2).The frontend-developer plugin has a stack-specific nunjucks-security hook that blocks inline scripts/styles. Backend plugins ship the equivalent for their template engine.
eval, Function(string), dynamic C#, or exec on user-supplied strings.pickle.loads on user data, BinaryFormatter, JSON.parse of untrusted input without a schema).rejectUnauthorized: false, ServicePointManager.ServerCertificateValidationCallback = (_, _, _, _) => true, verify=False).autoescape: false or rendering user input through | safe / Html.Raw.chmod 777 on a secrets file.If the user asks for any of the above, the agent refuses, names which standard is violated, and offers a compliant alternative.
User: "Just log the whole request body so I can debug — make a quick log line."
Agent response:
I can't log the full request body — Defra security and PII handling forbids logging raw user input because the body can contain names, emails, NI numbers, or other PII. Here is a compliant alternative that logs the diagnostic shape without the data:
import { logger } from '../config/logger.js' // pino is configured with redact paths in config/logger.js: // redact: ['req.body.email', 'req.body.dateOfBirth', 'req.headers.authorization'] // so even if a field slips through, it never reaches the log sink in plain text. request.logger.info( { route: request.path, method: request.method, fields: Object.keys(request.payload ?? {}), // shape only, not values userId: request.auth?.credentials?.userId // identifier, not PII }, 'registration form submitted' )If you need the actual values to debug a specific issue, capture them in a one-off scratch script that never runs in production, never gets committed, and is deleted when the bug is fixed.
The agent volunteers the redaction and identifier-only pattern without being asked.
docs/spec/PLAN.md "Decisions still required" in the upstream planning repo.gitleaks; if the project owner picks a different scanner, the secret-scan hook updates here.docs/requirements/non_goals.md "No GDPR-specific tooling beyond PII handling".What SKILL.md sets; muted values are Claude Code's defaults
5 skills in this plugin
/defra-accessibilityDefra accessibility expectations — WCAG 2.2 AA for code-generating roles (frontend, backend rendering HTML), and semantic-markup expectations for documentation roles. Use when the agent generates a page, a component, a markdown file, or any artefact that will be read by a screen reader, a keyboard-only user, or a user with reduced vision./defra-branchingDefra branching strategy — never commit or push directly to main or master. Use a feature branch named for the work, open a pull request, get review, then merge. Use when the agent is about to run git commit, git push, or git checkout, or when a developer asks how to start a piece of work./defra-Other plugins' skills for the same job
/defra-shared:defra-security-piifrom defra-shared
npx claudepluginhub defra/defra-ai-plugins --plugin defra-shared