[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AKDG45CQCBB70S0PAHJ15P":3,"skill-same:01M7AKDG45CQCBB70S0PAHJ15P":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M7AKDG45CQCBB70S0PAHJ15P","perl-security",null,"テイントモード、入力バリデーション、安全なプロセス実行、DBIパラメータ化クエリ、Webセキュリティ（XSS\u002FSQLi\u002FCSRF）、perlcriticセキュリティポリシーを網羅する包括的なPerlセキュリティ。","Cyrilthetecchieee\u002Fcyril-code-","Cyrilthetecchieee","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F219787998?v=4","01M7AF0MMMKRAA0H61XMJPV92H","Julian Cyril D ","01M7AF0MQ10AVG6QJQ1C2BC0F5",2,"MIT","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fja-JP\u002Fskills\u002Fperl-security\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: perl-security\ndescription: テイントモード、入力バリデーション、安全なプロセス実行、DBIパラメータ化クエリ、Webセキュリティ（XSS\u002FSQLi\u002FCSRF）、perlcriticセキュリティポリシーを網羅する包括的なPerlセキュリティ。\norigin: ECC\n---\n\n# Perlセキュリティパターン\n\n入力バリデーション、インジェクション防止、セキュアコーディングプラクティスを網羅するPerlアプリケーションの包括的なセキュリティガイドライン。\n\n## アクティベートするタイミング\n\n- Perlアプリケーションでユーザー入力を処理するとき\n- PerlのWebアプリケーション（CGI、Mojolicious、Dancer2、Catalyst）を構築するとき\n- セキュリティ脆弱性についてPerlコードをレビューするとき\n- ユーザー指定パスでファイル操作を実行するとき\n- PerlからシステムコマンドをExecuteするとき\n- DBIデータベースクエリを書くとき\n\n## 仕組み\n\nテイント対応の入力境界から始め、次に外側に移動する: 入力をバリデートしてアンテイントし、ファイルシステムとプロセス実行を制約内に保ち、どこでもパラメータ化されたDBIクエリを使用する。以下の例は、ユーザー入力、シェル、またはネットワークに触れるPerlコードをリリースする前に適用することが期待されるデフォルトを示す。\n\n## テイントモード\n\nPerlのテイントモード（`-T`）は外部ソースからのデータを追跡し、明示的なバリデーションなしに安全でない操作で使用されることを防ぐ。\n\n### テイントモードの有効化\n\n```perl\n#!\u002Fusr\u002Fbin\u002Fperl -T\nuse v5.36;\n\n# テイントされた: プログラム外からのもの\nmy $input    = $ARGV[0];        # テイントされた\nmy $env_path = $ENV{PATH};      # テイントされた\nmy $form     = \u003CSTDIN>;         # テイントされた\nmy $query    = $ENV{QUERY_STRING}; # テイントされた\n\n# PATHを早期にサニタイズ（テイントモードで必要）\n$ENV{PATH} = '\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin';\ndelete @ENV{qw(IFS CDPATH ENV BASH_ENV)};\n```\n\n### アンテイントパターン\n\n```perl\nuse v5.36;\n\n# Good: 特定の正規表現でバリデートしてアンテイント\nsub untaint_username($input) {\n    if ($input =~ \u002F^([a-zA-Z0-9_]{3,30})$\u002F) {\n        return $1;  # $1はアンテイントされている\n    }\n    die \"Invalid username: must be 3-30 alphanumeric characters\\n\";\n}\n\n# Good: ファイルパスをバリデートしてアンテイント\nsub untaint_filename($input) {\n    if ($input =~ m{^([a-zA-Z0-9._-]+)$}) {\n        return $1;\n    }\n    die \"Invalid filename: contains unsafe characters\\n\";\n}\n\n# Bad: 過度に許可的なアンテイント（目的を無効化する）\nsub bad_untaint($input) {\n    $input =~ \u002F^(.*)$\u002Fs;\n    return $1;  # 何でも受け入れる — 無意味\n}\n```\n\n## 入力バリデーション\n\n### ブロックリストよりアローリスト\n\n```perl\nuse v5.36;\n\n# Good: アローリスト — 許可されるものを正確に定義\nsub validate_sort_field($field) {\n    my %allowed = map { $_ => 1 } qw(name email created_at updated_at);\n    die \"Invalid sort field: $field\\n\" unless $allowed{$field};\n    return $field;\n}\n\n# Good: 特定のパターンでバリデート\nsub validate_email($email) {\n    if ($email =~ \u002F^([a-zA-Z0-9._%+-]+\\@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$\u002F) {\n        return $1;\n    }\n    die \"Invalid email address\\n\";\n}\n\nsub validate_integer($input) {\n    if ($input =~ \u002F^(-?\\d{1,10})$\u002F) {\n        return $1 + 0;  # 数値に強制変換\n    }\n    die \"Invalid integer\\n\";\n}\n\n# Bad: ブロックリスト — 常に不完全\nsub bad_validate($input) {\n    die \"Invalid\" if $input =~ \u002F[\u003C>\"';&|]\u002F;  # エンコードされた攻撃を見逃す\n    return $input;\n}\n```\n\n### 長さ制約\n\n```perl\nuse v5.36;\n\nsub validate_comment($text) {\n    die \"Comment is required\\n\"        unless length($text) > 0;\n    die \"Comment exceeds 10000 chars\\n\" if length($text) > 10_000;\n    return $text;\n}\n```\n\n## 安全な正規表現\n\n### ReDoS防止\n\n壊滅的なバックトラッキングは重複するパターンにネストされた量詞が使用されるときに発生する。\n\n```perl\nuse v5.36;\n\n# Bad: ReDoSに脆弱（指数的バックトラッキング）\nmy $bad_re = qr\u002F^(a+)+$\u002F;           # ネストされた量詞\nmy $bad_re2 = qr\u002F^([a-zA-Z]+)*$\u002F;   # クラスにネストされた量詞\nmy $bad_re3 = qr\u002F^(.*?,){10,}$\u002F;    # 繰り返される貪欲\u002F怠惰な組み合わせ\n\n# Good: ネストなしで書き直す\nmy $good_re = qr\u002F^a+$\u002F;             # 単一の量詞\nmy $good_re2 = qr\u002F^[a-zA-Z]+$\u002F;     # クラスに単一の量詞\n\n# Good: バックトラッキングを防ぐためにpossessive量詞またはアトミックグループを使用\nmy $safe_re = qr\u002F^[a-zA-Z]++$\u002F;             # Possessive (5.10+)\nmy $safe_re2 = qr\u002F^(?>a+)$\u002F;                # アトミックグループ\n\n# Good: 信頼されていないパターンにタイムアウトを適用\nuse POSIX qw(alarm);\nsub safe_match($string, $pattern, $timeout = 2) {\n    my $matched;\n    eval {\n        local $SIG{ALRM} = sub { die \"Regex timeout\\n\" };\n        alarm($timeout);\n        $matched = $string =~ $pattern;\n        alarm(0);\n    };\n    alarm(0);\n    die $@ if $@;\n    return $matched;\n}\n```\n\n## 安全なファイル操作\n\n### 3引数open\n\n```perl\nuse v5.36;\n\n# Good: 3引数open、レキシカルファイルハンドル、戻り値チェック\nsub read_file($path) {\n    open my $fh, '\u003C:encoding(UTF-8)', $path\n        or die \"Cannot open '$path': $!\\n\";\n    local $\u002F;\n    my $content = \u003C$fh>;\n    close $fh;\n    return $content;\n}\n\n# Bad: ユーザーデータを使った2引数open（コマンドインジェクション）\nsub bad_read($path) {\n    open my $fh, $path;        # $pathが\"|rm -rf \u002F\"なら、コマンドを実行！\n    open my $fh, \"\u003C $path\";   # シェルメタキャラクターインジェクション\n}\n```\n\n### TOCTOU防止とパストラバーサル\n\n```perl\nuse v5.36;\nuse Fcntl qw(:DEFAULT :flock);\nuse File::Spec;\nuse Cwd qw(realpath);\n\n# アトミックファイル作成\nsub create_file_safe($path) {\n    sysopen(my $fh, $path, O_WRONLY | O_CREAT | O_EXCL, 0600)\n        or die \"Cannot create '$path': $!\\n\";\n    return $fh;\n}\n\n# パスが許可されたディレクトリ内に留まることをバリデート\nsub safe_path($base_dir, $user_path) {\n    my $real = realpath(File::Spec->catfile($base_dir, $user_path))\n        \u002F\u002F die \"Path does not exist\\n\";\n    my $base_real = realpath($base_dir)\n        \u002F\u002F die \"Base dir does not exist\\n\";\n    die \"Path traversal blocked\\n\" unless $real =~ \u002F^\\Q$base_real\\E(?:\\\u002F|\\z)\u002F;\n    return $real;\n}\n```\n\n一時ファイルには`File::Temp`（`tempfile(UNLINK => 1)`）を使用し、レースコンディションを防ぐために`flock(LOCK_EX)`を使用する。\n\n## 安全なプロセス実行\n\n### リスト形式のsystemとexec\n\n```perl\nuse v5.36;\n\n# Good: リスト形式 — シェル補間なし\nsub run_command(@cmd) {\n    system(@cmd) == 0\n        or die \"Command failed: @cmd\\n\";\n}\n\nrun_command('grep', '-r', $user_pattern, '\u002Fvar\u002Flog\u002Fapp\u002F');\n\n# Good: IPC::Run3で安全に出力をキャプチャ\nuse IPC::Run3;\nsub capture_output(@cmd) {\n    my ($stdout, $stderr);\n    run3(\\@cmd, \\undef, \\$stdout, \\$stderr);\n    if ($?) {\n        die \"Command failed (exit $?): $stderr\\n\";\n    }\n    return $stdout;\n}\n\n# Bad: 文字列形式 — シェルインジェクション！\nsub bad_search($pattern) {\n    system(\"grep -r '$pattern' \u002Fvar\u002Flog\u002Fapp\u002F\");  # $patternが\"'; rm -rf \u002F #\"なら\n}\n\n# Bad: 補間のあるバッククォート\nmy $output = `ls $user_dir`;   # シェルインジェクションリスク\n```\n\n外部コマンドからstdout\u002Fstderrを安全にキャプチャするためには`Capture::Tiny`も使用する。\n\n## SQLインジェクション防止\n\n### DBIプレースホルダー\n\n```perl\nuse v5.36;\nuse DBI;\n\nmy $dbh = DBI->connect($dsn, $user, $pass, {\n    RaiseError => 1,\n    PrintError => 0,\n    AutoCommit => 1,\n});\n\n# Good: パラメータ化クエリ — 常にプレースホルダーを使用\nsub find_user($dbh, $email) {\n    my $sth = $dbh->prepare('SELECT * FROM users WHERE email = ?');\n    $sth->execute($email);\n    return $sth->fetchrow_hashref;\n}\n\nsub search_users($dbh, $name, $status) {\n    my $sth = $dbh->prepare(\n        'SELECT * FROM users WHERE name LIKE ? AND status = ? ORDER BY name'\n    );\n    $sth->execute(\"%$name%\", $status);\n    return $sth->fetchall_arrayref({});\n}\n\n# Bad: SQLでの文字列補間（SQLi脆弱性！）\nsub bad_find($dbh, $email) {\n    my $sth = $dbh->prepare(\"SELECT * FROM users WHERE email = '$email'\");\n    # $emailが\"' OR 1=1 --\"なら、すべてのユーザーが返される\n    $sth->execute;\n    return $sth->fetchrow_hashref;\n}\n```\n\n### 動的カラムアローリスト\n\n```perl\nuse v5.36;\n\n# Good: アローリストに対してカラム名をバリデート\nsub order_by($dbh, $column, $direction) {\n    my %allowed_cols = map { $_ => 1 } qw(name email created_at);\n    my %allowed_dirs = map { $_ => 1 } qw(ASC DESC);\n\n    die \"Invalid column: $column\\n\"    unless $allowed_cols{$column};\n    die \"Invalid direction: $direction\\n\" unless $allowed_dirs{uc $direction};\n\n    my $sth = $dbh->prepare(\"SELECT * FROM users ORDER BY $column $direction\");\n    $sth->execute;\n    return $sth->fetchall_arrayref({});\n}\n\n# Bad: ユーザー選択カラムを直接補間\nsub bad_order($dbh, $column) {\n    $dbh->prepare(\"SELECT * FROM users ORDER BY $column\");  # SQLi！\n}\n```\n\n### DBIx::Class（ORM安全性）\n\n```perl\nuse v5.36;\n\n# DBIx::Classは安全なパラメータ化クエリを生成する\nmy @users = $schema->resultset('User')->search({\n    status => 'active',\n    email  => { -like => '%@example.com' },\n}, {\n    order_by => { -asc => 'name' },\n    rows     => 50,\n});\n```\n\n## Webセキュリティ\n\n### XSS防止\n\n```perl\nuse v5.36;\nuse HTML::Entities qw(encode_entities);\nuse URI::Escape qw(uri_escape_utf8);\n\n# Good: HTMLコンテキスト用に出力をエンコード\nsub safe_html($user_input) {\n    return encode_entities($user_input);\n}\n\n# Good: URLコンテキスト用にエンコード\nsub safe_url_param($value) {\n    return uri_escape_utf8($value);\n}\n\n# Good: JSONコンテキスト用にエンコード\nuse JSON::MaybeXS qw(encode_json);\nsub safe_json($data) {\n    return encode_json($data);  # エスケープを処理\n}\n\n# テンプレートの自動エスケープ（Mojolicious）\n# \u003C%= $user_input %>   — 自動エスケープ（安全）\n# \u003C%== $raw_html %>    — 生の出力（危険、信頼されたコンテンツのみ）\n\n# テンプレートの自動エスケープ（Template Toolkit）\n# [% user_input | html %]  — 明示的なHTMLエンコード\n\n# Bad: HTMLの生の出力\nsub bad_html($input) {\n    print \"\u003Cdiv>$input\u003C\u002Fdiv>\";  # $inputが\u003Cscript>を含む場合XSS\n}\n```\n\n### CSRF保護\n\n```perl\nuse v5.36;\nuse Crypt::URandom qw(urandom);\nuse MIME::Base64 qw(encode_base64url);\n\nsub generate_csrf_token() {\n    return encode_base64url(urandom(32));\n}\n```\n\nトークンを検証するときは定数時間比較を使用する。ほとんどのWebフレームワーク（Mojolicious、Dancer2、Catalyst）には組み込みのCSRF保護がある — 手作りのソリューションよりそれらを優先する。\n\n### セッションとヘッダーセキュリティ\n\n```perl\nuse v5.36;\n\n# Mojolicousセッション + ヘッダー\n$app->secrets(['long-random-secret-rotated-regularly']);\n$app->sessions->secure(1);          # HTTPSのみ\n$app->sessions->samesite('Lax');\n\n$app->hook(after_dispatch => sub ($c) {\n    $c->res->headers->header('X-Content-Type-Options' => 'nosniff');\n    $c->res->headers->header('X-Frame-Options'        => 'DENY');\n    $c->res->headers->header('Content-Security-Policy' => \"default-src 'self'\");\n    $c->res->headers->header('Strict-Transport-Security' => 'max-age=31536000; includeSubDomains');\n});\n```\n\n## 出力エンコード\n\n常に出力をそのコンテキスト用にエンコードする: HTML用には`HTML::Entities::encode_entities()`、URL用には`URI::Escape::uri_escape_utf8()`、JSON用には`JSON::MaybeXS::encode_json()`。\n\n## CPANモジュールセキュリティ\n\n- cpanfileで**バージョンをピン留め**: `requires 'DBI', '== 1.643';`\n- **メンテナンスされたモジュールを優先**: MetaCPANで最近のリリースを確認\n- **依存関係を最小化**: 各依存関係は攻撃面積\n\n## セキュリティツーリング\n\n### perlcriticセキュリティポリシー\n\n```ini\n# .perlcriticrc — セキュリティ重視の設定\nseverity = 3\ntheme = security + core\n\n# 3引数openを要求\n[InputOutput::RequireThreeArgOpen]\nseverity = 5\n\n# チェックされたシステムコールを要求\n[InputOutput::RequireCheckedSyscalls]\nfunctions = :builtins\nseverity = 4\n\n# 文字列evalを禁止\n[BuiltinFunctions::ProhibitStringyEval]\nseverity = 5\n\n# バッククォート演算子を禁止\n[InputOutput::ProhibitBacktickOperators]\nseverity = 4\n\n# CGIでテイントチェックを要求\n[Modules::RequireTaintChecking]\nseverity = 5\n\n# 2引数openを禁止\n[InputOutput::ProhibitTwoArgOpen]\nseverity = 5\n\n# 裸のファイルハンドルを禁止\n[InputOutput::ProhibitBarewordFileHandles]\nseverity = 5\n```\n\n### perlcriticの実行\n\n```bash\n# ファイルをチェック\nperlcritic --severity 3 --theme security lib\u002FMyApp\u002FHandler.pm\n\n# プロジェクト全体をチェック\nperlcritic --severity 3 --theme security lib\u002F\n\n# CI統合\nperlcritic --severity 4 --theme security --quiet lib\u002F || exit 1\n```\n\n## クイックセキュリティチェックリスト\n\n| チェック | 確認事項 |\n|---|---|\n| テイントモード | CGI\u002FWebスクリプトの`-T`フラグ |\n| 入力バリデーション | アローリストパターン、長さ制限 |\n| ファイル操作 | 3引数open、パストラバーサルチェック |\n| プロセス実行 | リスト形式のsystem、シェル補間なし |\n| SQLクエリ | DBIプレースホルダー、補間しない |\n| HTML出力 | `encode_entities()`、テンプレート自動エスケープ |\n| CSRFトークン | 生成され、状態変更リクエストで検証される |\n| セッション設定 | Secure、HttpOnly、SameSiteクッキー |\n| HTTPヘッダー | CSP、X-Frame-Options、HSTS |\n| 依存関係 | ピン留めされたバージョン、監査されたモジュール |\n| 正規表現の安全性 | ネストされた量詞なし、アンカーされたパターン |\n| エラーメッセージ | スタックトレースやパスがユーザーに漏れない |\n\n## アンチパターン\n\n```perl\n# 1. ユーザーデータを使った2引数open（コマンドインジェクション）\nopen my $fh, $user_input;               # CRITICAL脆弱性\n\n# 2. 文字列形式のsystem（シェルインジェクション）\nsystem(\"convert $user_file output.png\"); # CRITICAL脆弱性\n\n# 3. SQL文字列補間\n$dbh->do(\"DELETE FROM users WHERE id = $id\");  # SQLi\n\n# 4. ユーザー入力でのeval（コードインジェクション）\neval $user_code;                         # リモートコード実行\n\n# 5. サニタイズせずに$ENVを信頼する\nmy $path = $ENV{UPLOAD_DIR};             # 操作される可能性がある\nsystem(\"ls $path\");                      # 二重脆弱性\n\n# 6. バリデーションなしにテイントを無効化\n($input) = $input =~ \u002F(.*)\u002Fs;           # 怠惰なアンテイント — 目的を無効化\n\n# 7. HTMLでの生のユーザーデータ\nprint \"\u003Cdiv>Welcome, $username!\u003C\u002Fdiv>\";  # XSS\n\n# 8. 未バリデートのリダイレクト\nprint $cgi->redirect($user_url);         # オープンリダイレクト\n```\n\n**忘れないこと**: Perlの柔軟性は強力だが規律が必要。Webに面したコードにはテイントモードを使用し、アローリストですべての入力をバリデートし、すべてのクエリにDBIプレースホルダーを使用し、すべての出力をそのコンテキスト用にエンコードする。多層防御 — 単一の層に依存しない。\n","# Perlセキュリティパターン\n\n入力バリデーション、インジェクション防止、セキュアコーディングプラクティスを網羅するPerlアプリケーションの包括的なセキュリティガイドライン。\n\n## アクティベートするタイミング\n\n- Perlアプリケーションでユーザー入力を処理するとき\n- PerlのWebアプリケーション（CGI、Mojolicious、Dancer2、Catalyst）を構築するとき\n- セキュリティ脆弱性についてPerlコードをレビューするとき\n- ユーザー指定パスでファイル操作を実行するとき\n- PerlからシステムコマンドをExecuteするとき\n- DBIデータベースクエリを書くとき\n\n## 仕組み\n\nテイント対応の入力境界から始め、次に外側に移動する: 入力をバリデートしてアンテイントし、ファイルシステムとプロセス実行を制約内に保ち、どこでもパラメータ化されたDBIクエリを使用する。以下の例は、ユーザー入力、シェル、またはネットワークに触れるPerlコードをリリースする前に適用することが期待されるデフォルトを示す。\n\n## テイントモード\n\nPerlのテイントモード（`-T`）は外部ソースからのデータを追跡し、明示的なバリデーションなしに安全でない操作で使用されることを防ぐ。\n\n### テイントモードの有効化\n\n```perl\n#!\u002Fusr\u002Fbin\u002Fperl -T\nuse v5.36;\n\n# テイントされた: プログラム外からのもの\nmy $input    = $ARGV[0];        # テイントされた\nmy $env_path = $ENV{PATH};      # テイントされた\nmy $form     = \u003CSTDIN>;         # テイントされた\nmy $query    = $ENV{QUERY_STRING}; # テイントされた\n\n# PATHを早期にサニタイズ（テイントモードで必要）\n$ENV{PATH} = '\u002Fusr\u002Flocal\u002Fbin:\u002Fusr\u002Fbin:\u002Fbin';\ndelete @ENV{qw(IFS CDPATH ENV BASH_ENV)};\n```\n\n### アンテイントパターン\n\n```perl\nuse v5.36;\n\n# Good: 特定の正規表現でバリデートしてアンテイント\nsub untaint_username($input) {\n    if ($input =~ \u002F^([a-zA-Z0-9_]{3,30})$\u002F) {\n        return $1;  # $1はアンテイントされている\n    }\n    die \"Invalid username: must be 3-30 alphanumeric characters\\n\";\n}\n\n# Good: ファイルパスをバリデートしてアンテイント\nsub untaint_filename($input) {\n    if ($input =~ m{^([a-zA-Z0-9._-]+)$}) {\n        return $1;\n    }\n    die \"Invalid filename: contains unsafe characters\\n\";\n}\n\n# Bad: 過度に許可的なアンテイント（目的を無効化する）\nsub bad_untaint($input) {\n    $input =~ \u002F^(.*)$\u002Fs;\n    return $1;  # 何でも受け入れる — 無意味\n}\n```\n\n## 入力バリデーション\n\n### ブロックリストよりアローリスト\n\n```perl\nuse v5.36;\n\n# Good: アローリスト — 許可されるものを正確に定義\nsub validate_sort_field($field) {\n    my %allowed = map { $_ => 1 } qw(name email created_at updated_at);\n    die \"Invalid sort field: $field\\n\" unless $allowed{$field};\n    return $field;\n}\n\n# Good: 特定のパターンでバリデート\nsub validate_email($email) {\n    if ($email =~ \u002F^([a-zA-Z0-9._%+-]+\\@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$\u002F) {\n        return $1;\n    }\n    die \"Invalid email address\\n\";\n}\n\nsub validate_integer($input) {\n    if ($input =~ \u002F^(-?\\d{1,10})$\u002F) {\n        return $1 + 0;  # 数値に強制変換\n    }\n    die \"Invalid integer\\n\";\n}\n\n# Bad: ブロックリスト — 常に不完全\nsub bad_validate($input) {\n    die \"Invalid\" if $input =~ \u002F[\u003C>\"';&|]\u002F;  # エンコードされた攻撃を見逃す\n    return $input;\n}\n```\n\n### 長さ制約\n\n```perl\nuse v5.36;\n\nsub validate_comment($text) {\n    die \"Comment is required\\n\"        unless length($text) > 0;\n    die \"Comment exceeds 10000 chars\\n\" if length($text) > 10_000;\n    return $text;\n}\n```\n\n## 安全な正規表現\n\n### ReDoS防止\n\n壊滅的なバックトラッキングは重複するパターンにネストされた量詞が使用されるときに発生する。\n\n```perl\nuse v5.36;\n\n# Bad: ReDoSに脆弱（指数的バックトラッキング）\nmy $bad_re = qr\u002F^(a+)+$\u002F;           # ネストされた量詞\nmy $bad_re2 = qr\u002F^([a-zA-Z]+)*$\u002F;   # クラスにネストされた量詞\nmy $bad_re3 = qr\u002F^(.*?,){10,}$\u002F;    # 繰り返される貪欲\u002F怠惰な組み合わせ\n\n# Good: ネストなしで書き直す\nmy $good_re = qr\u002F^a+$\u002F;             # 単一の量詞\nmy $good_re2 = qr\u002F^[a-zA-Z]+$\u002F;     # クラスに単一の量詞\n\n# Good: バックトラッキングを防ぐためにpossessive量詞またはアトミックグループを使用\nmy $safe_re = qr\u002F^[a-zA-Z]++$\u002F;             # Possessive (5.10+)\nmy $safe_re2 = qr\u002F^(?>a+)$\u002F;                # アトミックグループ\n\n# Good: 信頼されていないパターンにタイムアウトを適用\nuse POSIX qw(alarm);\nsub safe_match($string, $pattern, $timeout = 2) {\n    my $matched;\n    eval {\n        local $SIG{ALRM} = sub { die \"Regex timeout\\n\" };\n        alarm($timeout);\n        $matched = $string =~ $pattern;\n        alarm(0);\n    };\n    alarm(0);\n    die $@ if $@;\n    return $matched;\n}\n```\n\n## 安全なファイル操作\n\n### 3引数open\n\n```perl\nuse v5.36;\n\n# Good: 3引数open、レキシカルファイルハンドル、戻り値チェック\nsub read_file($path) {\n    open my $fh, '\u003C:encoding(UTF-8)', $path\n        or die \"Cannot open '$path': $!\\n\";\n    local $\u002F;\n    my $content = \u003C$fh>;\n    close $fh;\n    return $content;\n}\n\n# Bad: ユーザーデータを使った2引数open（コマンドインジェクション）\nsub bad_read($path) {\n    open my $fh, $path;        # $pathが\"|rm -rf \u002F\"なら、コマンドを実行！\n    open my $fh, \"\u003C $path\";   # シェルメタキャラクターインジェクション\n}\n```\n\n### TOCTOU防止とパストラバーサル\n\n```perl\nuse v5.36;\nuse Fcntl qw(:DEFAULT :flock);\nuse File::Spec;\nuse Cwd qw(realpath);\n\n# アトミックファイル作成\nsub create_file_safe($path) {\n    sysopen(my $fh, $path, O_WRONLY | O_CREAT | O_EXCL, 0600)\n        or die \"Cannot create '$path': $!\\n\";\n    return $fh;\n}\n\n# パスが許可されたディレクトリ内に留まることをバリデート\nsub safe_path($base_dir, $user_path) {\n    my $real = realpath(File::Spec->catfile($base_dir, $user_path))\n        \u002F\u002F die \"Path does not exist\\n\";\n    my $base_real = realpath($base_dir)\n        \u002F\u002F die \"Base dir does not exist\\n\";\n    die \"Path traversal blocked\\n\" unless $real =~ \u002F^\\Q$base_real\\E(?:\\\u002F|\\z)\u002F;\n    return $real;\n}\n```\n\n一時ファイルには`File::Temp`（`tempfile(UNLINK => 1)`）を使用し、レースコンディションを防ぐために`flock(LOCK_EX)`を使用する。\n\n## 安全なプロセス実行\n\n### リスト形式のsystemとexec\n\n```perl\nuse v5.36;\n\n# Good: リスト形式 — シェル補間なし\nsub run_command(@cmd) {\n    system(@cmd) == 0\n        or die \"Command failed: @cmd\\n\";\n}\n\nrun_command('grep', '-r', $user_pattern, '\u002Fvar\u002Flog\u002Fapp\u002F');\n\n# Good: IPC::Run3で安全に出力をキャプチャ\nuse IPC::Run3;\nsub capture_output(@cmd) {\n    my ($stdout, $stderr);\n    run3(\\@cmd, \\undef, \\$stdout, \\$stderr);\n    if ($?) {\n        die \"Command failed (exit $?): $stderr\\n\";\n    }\n    return $stdout;\n}\n\n# Bad: 文字列形式 — シェルインジェクション！\nsub bad_search($pattern) {\n    system(\"grep -r '$pattern' \u002Fvar\u002Flog\u002Fapp\u002F\");  # $patternが\"'; rm -rf \u002F #\"なら\n}\n\n# Bad: 補間のあるバッククォート\nmy $output = `ls $user_dir`;   # シェルインジェクションリスク\n```\n\n外部コマンドからstdout\u002Fstderrを安全にキャプチャするためには`Capture::Tiny`も使用する。\n\n## SQLインジェクション防止\n\n### DBIプレースホルダー\n\n```perl\nuse v5.36;\nuse DBI;\n\nmy $dbh = DBI->connect($dsn, $user, $pass, {\n    RaiseError => 1,\n    PrintError => 0,\n    AutoCommit => 1,\n});\n\n# Good: パラメータ化クエリ — 常にプレースホルダーを使用\nsub find_user($dbh, $email) {\n    my $sth = $dbh->prepare('SELECT * FROM users WHERE email = ?');\n    $sth->execute($email);\n    return $sth->fetchrow_hashref;\n}\n\nsub search_users($dbh, $name, $status) {\n    my $sth = $dbh->prepare(\n        'SELECT * FROM users WHERE name LIKE ? AND status = ? ORDER BY name'\n    );\n    $sth->execute(\"%$name%\", $status);\n    return $sth->fetchall_arrayref({});\n}\n\n# Bad: SQLでの文字列補間（SQLi脆弱性！）\nsub bad_find($dbh, $email) {\n    my $sth = $dbh->prepare(\"SELECT * FROM users WHERE email = '$email'\");\n    # $emailが\"' OR 1=1 --\"なら、すべてのユーザーが返される\n    $sth->execute;\n    return $sth->fetchrow_hashref;\n}\n```\n\n### 動的カラムアローリスト\n\n```perl\nuse v5.36;\n\n# Good: アローリストに対してカラム名をバリデート\nsub order_by($dbh, $column, $direction) {\n    my %allowed_cols = map { $_ => 1 } qw(name email created_at);\n    my %allowed_dirs = map { $_ => 1 } qw(ASC DESC);\n\n    die \"Invalid column: $column\\n\"    unless $allowed_cols{$column};\n    die \"Invalid direction: $direction\\n\" unless $allowed_dirs{uc $direction};\n\n    my $sth = $dbh->prepare(\"SELECT * FROM users ORDER BY $column $direction\");\n    $sth->execute;\n    return $sth->fetchall_arrayref({});\n}\n\n# Bad: ユーザー選択カラムを直接補間\nsub bad_order($dbh, $column) {\n    $dbh->prepare(\"SELECT * FROM users ORDER BY $column\");  # SQLi！\n}\n```\n\n### DBIx::Class（ORM安全性）\n\n```perl\nuse v5.36;\n\n# DBIx::Classは安全なパラメータ化クエリを生成する\nmy @users = $schema->resultset('User')->search({\n    status => 'active',\n    email  => { -like => '%@example.com' },\n}, {\n    order_by => { -asc => 'name' },\n    rows     => 50,\n});\n```\n\n## Webセキュリティ\n\n### XSS防止\n\n```perl\nuse v5.36;\nuse HTML::Entities qw(encode_entities);\nuse URI::Escape qw(uri_escape_utf8);\n\n# Good: HTMLコンテキスト用に出力をエンコード\nsub safe_html($user_input) {\n    return encode_entities($user_input);\n}\n\n# Good: URLコンテキスト用にエンコード\nsub safe_url_param($value) {\n    return uri_escape_utf8($value);\n}\n\n# Good: JSONコンテキスト用にエンコード\nuse JSON::MaybeXS qw(encode_json);\nsub safe_json($data) {\n    return encode_json($data);  # エスケープを処理\n}\n\n# テンプレートの自動エスケープ（Mojolicious）\n# \u003C%= $user_input %>   — 自動エスケープ（安全）\n# \u003C%== $raw_html %>    — 生の出力（危険、信頼されたコンテンツのみ）\n\n# テンプレートの自動エスケープ（Template Toolkit）\n# [% user_input | html %]  — 明示的なHTMLエンコード\n\n# Bad: HTMLの生の出力\nsub bad_html($input) {\n    print \"\u003Cdiv>$input\u003C\u002Fdiv>\";  # $inputが\u003Cscript>を含む場合XSS\n}\n```\n\n### CSRF保護\n\n```perl\nuse v5.36;\nuse Crypt::URandom qw(urandom);\nuse MIME::Base64 qw(encode_base64url);\n\nsub generate_csrf_token() {\n    return encode_base64url(urandom(32));\n}\n```\n\nトークンを検証するときは定数時間比較を使用する。ほとんどのWebフレームワーク（Mojolicious、Dancer2、Catalyst）には組み込みのCSRF保護がある — 手作りのソリューションよりそれらを優先する。\n\n### セッションとヘッダーセキュリティ\n\n```perl\nuse v5.36;\n\n# Mojolicousセッション + ヘッダー\n$app->secrets(['long-random-secret-rotated-regularly']);\n$app->sessions->secure(1);          # HTTPSのみ\n$app->sessions->samesite('Lax');\n\n$app->hook(after_dispatch => sub ($c) {\n    $c->res->headers->header('X-Content-Type-Options' => 'nosniff');\n    $c->res->headers->header('X-Frame-Options'        => 'DENY');\n    $c->res->headers->header('Content-Security-Policy' => \"default-src 'self'\");\n    $c->res->headers->header('Strict-Transport-Security' => 'max-age=31536000; includeSubDomains');\n});\n```\n\n## 出力エンコード\n\n常に出力をそのコンテキスト用にエンコードする: HTML用には`HTML::Entities::encode_entities()`、URL用には`URI::Escape::uri_escape_utf8()`、JSON用には`JSON::MaybeXS::encode_json()`。\n\n## CPANモジュールセキュリティ\n\n- cpanfileで**バージョンをピン留め**: `requires 'DBI', '== 1.643';`\n- **メンテナンスされたモジュールを優先**: MetaCPANで最近のリリースを確認\n- **依存関係を最小化**: 各依存関係は攻撃面積\n\n## セキュリティツーリング\n\n### perlcriticセキュリティポリシー\n\n```ini\n# .perlcriticrc — セキュリティ重視の設定\nseverity = 3\ntheme = security + core\n\n# 3引数openを要求\n[InputOutput::RequireThreeArgOpen]\nseverity = 5\n\n# チェックされたシステムコールを要求\n[InputOutput::RequireCheckedSyscalls]\nfunctions = :builtins\nseverity = 4\n\n# 文字列evalを禁止\n[BuiltinFunctions::ProhibitStringyEval]\nseverity = 5\n\n# バッククォート演算子を禁止\n[InputOutput::ProhibitBacktickOperators]\nseverity = 4\n\n# CGIでテイントチェックを要求\n[Modules::RequireTaintChecking]\nseverity = 5\n\n# 2引数openを禁止\n[InputOutput::ProhibitTwoArgOpen]\nseverity = 5\n\n# 裸のファイルハンドルを禁止\n[InputOutput::ProhibitBarewordFileHandles]\nseverity = 5\n```\n\n### perlcriticの実行\n\n```bash\n# ファイルをチェック\nperlcritic --severity 3 --theme security lib\u002FMyApp\u002FHandler.pm\n\n# プロジェクト全体をチェック\nperlcritic --severity 3 --theme security lib\u002F\n\n# CI統合\nperlcritic --severity 4 --theme security --quiet lib\u002F || exit 1\n```\n\n## クイックセキュリティチェックリスト\n\n| チェック | 確認事項 |\n|---|---|\n| テイントモード | CGI\u002FWebスクリプトの`-T`フラグ |\n| 入力バリデーション | アローリストパターン、長さ制限 |\n| ファイル操作 | 3引数open、パストラバーサルチェック |\n| プロセス実行 | リスト形式のsystem、シェル補間なし |\n| SQLクエリ | DBIプレースホルダー、補間しない |\n| HTML出力 | `encode_entities()`、テンプレート自動エスケープ |\n| CSRFトークン | 生成され、状態変更リクエストで検証される |\n| セッション設定 | Secure、HttpOnly、SameSiteクッキー |\n| HTTPヘッダー | CSP、X-Frame-Options、HSTS |\n| 依存関係 | ピン留めされたバージョン、監査されたモジュール |\n| 正規表現の安全性 | ネストされた量詞なし、アンカーされたパターン |\n| エラーメッセージ | スタックトレースやパスがユーザーに漏れない |\n\n## アンチパターン\n\n```perl\n# 1. ユーザーデータを使った2引数open（コマンドインジェクション）\nopen my $fh, $user_input;               # CRITICAL脆弱性\n\n# 2. 文字列形式のsystem（シェルインジェクション）\nsystem(\"convert $user_file output.png\"); # CRITICAL脆弱性\n\n# 3. SQL文字列補間\n$dbh->do(\"DELETE FROM users WHERE id = $id\");  # SQLi\n\n# 4. ユーザー入力でのeval（コードインジェクション）\neval $user_code;                         # リモートコード実行\n\n# 5. サニタイズせずに$ENVを信頼する\nmy $path = $ENV{UPLOAD_DIR};             # 操作される可能性がある\nsystem(\"ls $path\");                      # 二重脆弱性\n\n# 6. バリデーションなしにテイントを無効化\n($input) = $input =~ \u002F(.*)\u002Fs;           # 怠惰なアンテイント — 目的を無効化\n\n# 7. HTMLでの生のユーザーデータ\nprint \"\u003Cdiv>Welcome, $username!\u003C\u002Fdiv>\";  # XSS\n\n# 8. 未バリデートのリダイレクト\nprint $cgi->redirect($user_url);         # オープンリダイレクト\n```\n\n**忘れないこと**: Perlの柔軟性は強力だが規律が必要。Webに面したコードにはテイントモードを使用し、アローリストですべての入力をバリデートし、すべてのクエリにDBIプレースホルダーを使用し、すべての出力をそのコンテキスト用にエンコードする。多層防御 — 単一の層に依存しない。\n",{"name":5,"origin":24,"description":7},"ECC","main","57e7aa6b6e03bce1a7d7862ba9c2ec312f7f19b5","src\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fja-JP\u002Fskills\u002Fperl-security",0,"https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee","https:\u002F\u002Fwithcyril.me\u002F","Hi, I’m Julian Cyril D, a Computer Science and Business Systems student at PSNACET.\r\nI’m passionate about full-stack development, UI\u002FUX design, and building sma","2026-11-04 23:28:50",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add Cyrilthetecchieee\u002Fcyril-code- --skill perl-security",{"tool":40,"command":41},"bunx","bunx skills add Cyrilthetecchieee\u002Fcyril-code- --skill perl-security",{"tool":43,"command":44},"pnpm","pnpm dlx skills add Cyrilthetecchieee\u002Fcyril-code- --skill perl-security","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fja-JP\u002Fskills\u002Fperl-security\u002FSKILL.md",true,[],[49,58,65,73,80,87],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":54,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":19},"01M7AQV6CYX8RMC78420V9WZ62","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7AQV2895N3S1MEX6K76G6G2","youtube-downloader","Download YouTube videos with customizable quality and format options. Use this skill when the user asks to download, save, or grab YouTube videos. Supports various quality settings (best, 1080p, 720p, 480p, 360p), multiple formats (mp4, webm, mkv), and audio-only downloads as MP3.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fvideo-downloader\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":69,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7AQTRNX62DNKVZ5GXEHRBKB","theme-factory","Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors\u002Ffonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftheme-factory\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftheme-factory\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7AQTNNVHAAN9H6DA8T6ZVE0","template-skill","Replace with description of the skill and when Claude should use it.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftemplate-skill\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M7AQTJ3MQ6AKX152MEX2MYCC","tailored-resume-generator","Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftailored-resume-generator\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":91,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7AQTD7D5MYET2YWG7HG9WM3","slack-gif-creator","Toolkit for creating animated GIFs optimized for Slack, with validators for size constraints and composable animation primitives. This skill applies when users request animated GIFs or emoji animations for Slack from descriptions like \"make me a GIF for Slack of X doing Y\".","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fslack-gif-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fslack-gif-creator\u002FSKILL.md",[],[]]