Skip to content

CTF 定義をページから分離して features/ctf モジュール群へ移動#19

Merged
T3pp31 merged 4 commits into
mainfrom
codex/refactor-ctf-definitions-into-modules
May 14, 2026
Merged

CTF 定義をページから分離して features/ctf モジュール群へ移動#19
T3pp31 merged 4 commits into
mainfrom
codex/refactor-ctf-definitions-into-modules

Conversation

@T3pp31

@T3pp31 T3pp31 commented May 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • CtfPage に埋め込まれていた CTF の項目・変換・検出ルールを分離して責務を分け、今後 UI や設定から拡張しやすい構造にするため。
  • flag 形式を固定値にせず正規表現リストで管理できるようにして、UI からの追加を想定した拡張性を確保するため。

Description

  • 型定義を追加し、src/features/ctf/types.tsCtfTransform / CtfDetector / CtfDetection / FlagPattern / CtfHintSection などを定義しました。
  • 変換群を src/features/ctf/transforms.ts として分離し、各 transform は id/label/category/descriptionrun(input, options) を持つ構造にしました(例:Base64, URL, Hex, ROT13)。
  • 検出器群を src/features/ctf/detectors.ts として分離し、検出は type/confidence/range/recommendedActions を返すように実装し、検出の重複を除去するロジックを追加しました(重なりの高いものを優先して一意化)。
  • flag の初期パターンを src/features/ctf/flagPatterns.tsDEFAULT_FLAG_PATTERNS として定義し、flag{...}/ctf{...}/HTB{...}/picoCTF{...} を用意して正規表現で管理可能にしました(buildFlagPatternRegex を提供)。
  • 元のヒント定義を src/features/ctf/hints.ts に移動し、src/pages/CtfPage.tsx はこれらのモジュールをインポートして表示するように更新しました。
  • 追加で tests/ctfFeatures.test.ts を追加し、transform メタデータ・Base64 往復変換・初期 flag パターン・検出範囲・カスタムパターン受け入れを検証するテストを実装しました。

Testing

  • npm run lint を実行してリンティングは成功しました。
  • npm run build を実行してビルドは成功しました。
  • npx vitest run を実行してテストスイートは成功し、最終的に全 58 テストがパスしました(新規の tests/ctfFeatures.test.ts を含む)。

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9576efb1bc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/features/ctf/detectors.ts Outdated

const BASE64_CANDIDATE_PATTERN = /(?:[A-Za-z0-9+/]{4}){3,}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/g;
const HEX_CANDIDATE_PATTERN = /(?:0x)?(?:[0-9a-fA-F]{2}[\s:-]?){4,}/g;
const URL_ENCODED_PATTERN = /%(?:[0-9a-fA-F]{2})/g;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Group contiguous URL-encoded bytes

When the input contains a normal URL-encoded token such as %66%6c%61%67%7B...%7D, this pattern matches each %xx escape separately, so the detector returns many 3-character ranges and the suggested url-decode action only decodes one byte at a time. Any consumer that applies actions to the returned ranges cannot recover the full encoded flag/string; the regex should match a contiguous encoded run instead, e.g. one or more %HH groups.

Useful? React with 👍 / 👎.

T3pp31 commented May 14, 2026

Copy link
Copy Markdown
Owner Author

確認しましたが、この PR は現状マージしません。

理由:

  • main の最新状態にある CI 関連ファイルを削除する差分が入っています。ローカルで origin/main..origin/pr/19 を確認すると、.github/workflows/ci.ymltests/ciWorkflowConsistency.test.mjstests/readmeConsistency.test.mjs などが削除対象になっていました。まず main を取り込んで、CI と整合性テストを維持してください。
  • src/features/ctf/*src/pages/CtfPage.tsxAdd CTF Workspace and Artifact Analyzer (binary analysis, transforms, detectors) #17CTF ワークスペースの状態モデルと Writeup エクスポートを追加 #20CTFワークスペースを追加 #22 と変更領域が重複しています。先に CTF feature API と CtfPage.tsx の所有方針を一本化してください。
  • URL encoded 検出が /%(?:[0-9a-fA-F]{2})/g のため、%66%6c%61%67 のような連続した URL エンコード文字列を 1 文字単位の検出に分割します。ワークスペースで「候補」として扱うなら、連続した %xx シーケンスを 1 件として検出した方が後続の decode 操作に繋げやすいです。

対応案:

  1. main に rebase/merge して CI 削除差分を消す。
  2. URL_ENCODED_PATTERN を連続シーケンス単位に修正し、テストを追加する。
  3. Add CTF Workspace and Artifact Analyzer (binary analysis, transforms, detectors) #17/CTF ワークスペースの状態モデルと Writeup エクスポートを追加 #20/CTFワークスペースを追加 #22 との重複を整理して、CTF module の採用形を 1 つにしてください。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0aadf764a3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


const BASE64_CANDIDATE_PATTERN = /(?:[A-Za-z0-9+/]{4}){3,}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/g;
const HEX_CANDIDATE_PATTERN = /(?:0x)?(?:[0-9a-fA-F]{2}[\s:-]?){4,}/g;
const URL_ENCODED_PATTERN = /(?:%[0-9a-fA-F]{2})+/g;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include mixed URL-encoded runs

For URL-encoded strings that contain ordinary safe characters between escapes (for example %66%6c%61%67%7Bsample%7D), this regex still stops at sample, returning two detections instead of the full token. Fresh evidence beyond the earlier byte-grouping comment is that the new test expects this exact mixed string to be one range through input.length; with the current pattern, any consumer applying url-decode to the detected range cannot recover the complete flag.

Useful? React with 👍 / 👎.

@T3pp31 T3pp31 merged commit 3401495 into main May 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant