Perl Security Patterns
Comprehensive security guidelines for Perl applications covering input validation, injection prevention, and secure coding practices.
When to Activate
- Handling user input in Perl applications
- Building Perl web applications (CGI, Mojolicious, Dancer2, Catalyst)
- Reviewing Perl code for security vulnerabilities
- Performing file operations with user-supplied paths
- Executing system commands from Perl
- Writing DBI database queries
When NOT to Use
- Other languages (use
django-security, laravel-security, security-review, etc.)
- General Perl idioms (use
perl-patterns)
- Automated SaaS scanning (use
vibe-security-scanner)
How It Works
Start with taint-aware input boundaries, then move outward: validate and untaint inputs, keep filesystem and process execution constrained, and use parameterized DBI queries everywhere. The examples below show the safe defaults this skill expects you to apply before shipping Perl code that touches user input, the shell, or the network.
Contents
| Topic |
Reference |
Taint mode (-T, untainting) |
references/taint-mode.md |
| Input validation (allowlist, length) |
references/input-validation.md |
| Safe regex (ReDoS prevention) |
references/safe-regex.md |
| Safe file ops (three-arg open, TOCTOU) |
references/safe-file-ops.md |
| Safe process execution (list-form) |
references/safe-process.md |
| SQL injection (DBI placeholders, ORM) |
references/sql-injection.md |
| Web security (XSS, CSRF, sessions) |
references/web-security.md |
| Tooling (perlcritic policies, CI) |
references/security-tooling.md |
Output Encoding
Always encode output for its context: HTML::Entities::encode_entities() for HTML, URI::Escape::uri_escape_utf8() for URLs, JSON::MaybeXS::encode_json() for JSON.
CPAN Module Security
- Pin versions in cpanfile:
requires 'DBI', '== 1.643';
- Prefer maintained modules: Check MetaCPAN for recent releases
- Minimize dependencies: Each dependency is an attack surface
Quick Security Checklist
| Check |
What to Verify |
| Taint mode |
-T flag on CGI/web scripts |
| Input validation |
Allowlist patterns, length limits |
| File operations |
Three-arg open, path traversal checks |
| Process execution |
List-form system, no shell interpolation |
| SQL queries |
DBI placeholders, never interpolate |
| HTML output |
encode_entities(), template auto-escape |
| CSRF tokens |
Generated, verified on state-changing requests |
| Session config |
Secure, HttpOnly, SameSite cookies |
Exemplo
#!/usr/bin/perl -T
my ($id) = $cgi->param('id') =~ /^([0-9]+)$/ or die "bad id";
open(my $fh, '<', $file) or die; # three-arg, sem shell
$dbh->do("SELECT * FROM u WHERE id=?", undef, $id); # placeholder, nunca interpola
print encode_entities($name); # output encoding por contexto
1---2name: perl-security3description: "Use when comprehensive Perl security covering taint mode, input validation, safe process execution, DBI parameterized queries, web security (XSS/SQLi/CSRF), and perlcritic security policies. Only for Perl — not for other languages. Triggers on \"perl-security\", \"perl security\", \"security\"."4metadata:5 source: https://skillmd.com/skills/majinmagros/perl-security6 origin: ECC7---89# Perl Security Patterns1011Comprehensive security guidelines for Perl applications covering input validation, injection prevention, and secure coding practices.1213## When to Activate1415- Handling user input in Perl applications16- Building Perl web applications (CGI, Mojolicious, Dancer2, Catalyst)17- Reviewing Perl code for security vulnerabilities18- Performing file operations with user-supplied paths19- Executing system commands from Perl20- Writing DBI database queries2122## When NOT to Use2324- Other languages (use `django-security`, `laravel-security`, `security-review`, etc.)25- General Perl idioms (use `perl-patterns`)26- Automated SaaS scanning (use `vibe-security-scanner`)2728## How It Works2930Start with taint-aware input boundaries, then move outward: validate and untaint inputs, keep filesystem and process execution constrained, and use parameterized DBI queries everywhere. The examples below show the safe defaults this skill expects you to apply before shipping Perl code that touches user input, the shell, or the network.3132## Contents3334| Topic | Reference |35|---|---|36| Taint mode (`-T`, untainting) | `references/taint-mode.md` |37| Input validation (allowlist, length) | `references/input-validation.md` |38| Safe regex (ReDoS prevention) | `references/safe-regex.md` |39| Safe file ops (three-arg open, TOCTOU) | `references/safe-file-ops.md` |40| Safe process execution (list-form) | `references/safe-process.md` |41| SQL injection (DBI placeholders, ORM) | `references/sql-injection.md` |42| Web security (XSS, CSRF, sessions) | `references/web-security.md` |43| Tooling (perlcritic policies, CI) | `references/security-tooling.md` |4445## Output Encoding4647Always encode output for its context: `HTML::Entities::encode_entities()` for HTML, `URI::Escape::uri_escape_utf8()` for URLs, `JSON::MaybeXS::encode_json()` for JSON.4849## CPAN Module Security5051- **Pin versions** in cpanfile: `requires 'DBI', '== 1.643';`52- **Prefer maintained modules**: Check MetaCPAN for recent releases53- **Minimize dependencies**: Each dependency is an attack surface5455## Quick Security Checklist5657| Check | What to Verify |58|---|---|59| Taint mode | `-T` flag on CGI/web scripts |60| Input validation | Allowlist patterns, length limits |61| File operations | Three-arg open, path traversal checks |62| Process execution | List-form system, no shell interpolation |63| SQL queries | DBI placeholders, never interpolate |64| HTML output | `encode_entities()`, template auto-escape |65| CSRF tokens | Generated, verified on state-changing requests |66| Session config | Secure, HttpOnly, SameSite cookies |6768## Exemplo6970```perl71#!/usr/bin/perl -T72my ($id) = $cgi->param('id') =~ /^([0-9]+)$/ or die "bad id";73open(my $fh, '<', $file) or die; # three-arg, sem shell74$dbh->do("SELECT * FROM u WHERE id=?", undef, $id); # placeholder, nunca interpola75print encode_entities($name); # output encoding por contexto76```