สร้าง Security Test อัตโนมัติด้วย owasp/skill
June 2026 · Peerapat A · ← Agentic AI
Automate Security Testing with an AI Skill
Bottom Line Up Front: You can build a reusable Claude Code skill to automatically generate OWASP Top 10 security tests using PlaySpec and FakeRequest. This ensures consistent security testing across your Play Framework controllers.
Writing security tests is tedious, repetitive, and easy to skip when a deadline is close. But it is also exactly the kind of work an AI assistant is good at — well-defined patterns, repeated across many endpoints. Instead of asking Claude the same thing every time, you can capture that knowledge once as a skill and reuse it forever.
This post walks through a custom Claude Code skill that turns any Play Framework controller
into a full OWASP Top 10 security test suite using
What is a Skill?
A skill is a reusable instruction set you give to an AI agent. It is a Markdown file with a small frontmatter header and a body of instructions. When you invoke it, the agent loads those instructions as expert context — so it behaves like a specialist instead of a generalist.
The frontmatter has three useful fields:
- name — the identifier you invoke the skill by.
- description — a one-line summary the agent uses to decide when the skill is relevant.
- argument-hint — tells the user what input to provide (here, a controller or route).
The Skill Definition
Here is the full skill. It tells the agent to act as a security-focused SDET and produce integration tests against the OWASP Top 10 — not generic unit tests.
---
name: owasp-playspec-tester
description: "Generates Scala Play Framework security tests using
PlaySpec and FakeRequest based on OWASP Top 10 vulnerabilities."
argument-hint: "Specify the target Play controller or endpoint route
to generate tests for."
---
# OWASP Play Framework Security Tester
You are an expert Security Software Development Engineer in Test (SDET).
Your task is to generate automated security integration tests for Play
Framework applications using PlaySpec, FakeRequest, and ScalaTest.
## Instructions
When the user provides a controller, model, or route, generate a
PlaySpec test class that verifies the application's resilience against
OWASP Top 10 2025 vulnerabilities.
The Test Coverage It Enforces
The heart of the skill is a checklist of attack classes. Every generated suite must cover all four, so nothing gets quietly skipped:
-
Injection (SQL/NoSQL/Command) — sends payloads like
' OR 1=1 -- and asserts the response is400 BAD_REQUEST or401 UNAUTHORIZED , never a leaky500 INTERNAL_SERVER_ERROR . -
Cross-Site Scripting (XSS) — injects
<script>alert(1)</script> into JSON or form bodies and asserts the raw payload is not reflected back unescaped. -
Security Misconfiguration — checks that responses carry secure headers
(
X-Frame-Options ,X-Content-Type-Options ,Content-Security-Policy ). -
Broken Access Control — hits restricted endpoints with no valid session or JWT
and asserts
401 UNAUTHORIZED or403 FORBIDDEN .
Code Guidelines
The skill also pins down how the tests are written, so the output is consistent and runnable:
- Seed test data in a
def initial(): Unit to simulate records in the database. - Use
play.api.test.FakeRequest to simulate malicious traffic. - Use
play.api.test.Helpers._ for routing and assertions (status(result) ,contentAsString(result) ). - Produce valid Scala in ScalaTest BDD style:
"Endpoint" should { "reject..." in { ... } } .
What the Output Looks Like
Point the skill at a controller and it produces a ready-to-run spec. A trimmed example:
class UserControllerSecuritySpec extends PlaySpec with GuiceOneAppPerSuite {
def initial(): Unit = {
// seed a known user to attack against
}
"UserController" should {
"reject SQL injection in the login field" in {
val payload = Json.obj("username" -> "' OR 1=1 --", "password" -> "x")
val request = FakeRequest(POST, "/login").withJsonBody(payload)
val result = route(app, request).get
status(result) must (be(BAD_REQUEST) or be(UNAUTHORIZED))
status(result) mustNot be(INTERNAL_SERVER_ERROR)
}
"escape XSS payloads in the profile name" in {
val payload = Json.obj("name" -> "<script>alert(1)</script>")
val request = FakeRequest(POST, "/profile").withJsonBody(payload)
val result = route(app, request).get
contentAsString(result) mustNot include("<script>")
}
"return secure headers on the home page" in {
val result = route(app, FakeRequest(GET, "/")).get
header("X-Frame-Options", result) mustBe defined
header("X-Content-Type-Options", result) mustBe defined
header("Content-Security-Policy", result) mustBe defined
}
"block access to admin without a token" in {
val result = route(app, FakeRequest(GET, "/admin")).get
status(result) must (be(UNAUTHORIZED) or be(FORBIDDEN))
}
}
}
Why Capture It as a Skill
- ✅ Consistency — every endpoint gets the same four attack classes, every time.
- ✅ Speed — no re-explaining the requirements on each new controller.
- ✅ Shared standard — the whole team invokes the same security baseline.
- ✅ Living documentation — the skill file is your security testing policy.
Bottom Line
Security testing does not have to be the task everyone avoids. By encoding the OWASP Top 10 into a small, reusable skill, you turn a chore into a one-line command — and make "did we test for injection?" a question with a reliable answer.
Generated tests are a starting point, not a guarantee. Always review them and pair with manual security review for high-risk endpoints.
สร้าง Security Test อัตโนมัติด้วย owasp/skill
สรุปประเด็นสำคัญ (BLUF): คุณสามารถสร้าง Claude Code skill เพื่อช่วยเขียนชุดทดสอบความปลอดภัยตามมาตรฐาน OWASP Top 10 อัตโนมัติด้วย PlaySpec และ FakeRequest ทำให้การทดสอบความปลอดภัยของ Play Framework controller มีมาตรฐานเดียวกัน
การเขียน security tests เป็นงานที่น่าเบื่อ ซ้ำซาก และมักจะถูกข้ามไปง่ายๆ เมื่อใกล้ถึง deadline แต่นี่ก็คืองานประเภทที่ AI assistant ถนัดที่สุด — ด้วยรูปแบบที่ชัดเจนและทำซ้ำในหลายๆ endpoints แทนที่จะต้องสั่ง Claude แบบเดิมๆ ทุกครั้ง คุณสามารถรวบรวมความรู้นั้นไว้ครั้งเดียวในรูปแบบของ skill และนำกลับมาใช้ใหม่ได้ตลอดไป
บทความนี้จะพาไปดูการสร้าง custom Claude Code skill ที่จะเปลี่ยน Play Framework controller ใดๆ
ให้เป็น security test suite แบบเต็มรูปแบบตามมาตรฐาน OWASP Top 10 โดยใช้
What is a Skill?
skill คือชุดคำสั่งที่สามารถนำกลับมาใช้ใหม่ได้ ซึ่งคุณกำหนดให้กับ AI agent มันเป็นไฟล์ Markdown ที่มี frontmatter header เล็กๆ และส่วนของเนื้อหาคำสั่ง เมื่อคุณ invoke มัน ตัว agent จะโหลดคำสั่งเหล่านั้น เป็น expert context — ทำให้มันทำงานได้เหมือนผู้เชี่ยวชาญเฉพาะทางแทนที่จะเป็นแบบทั่วไป
frontmatter มีฟิลด์ที่มีประโยชน์ 3 อย่าง:
- name — ตัวระบุ (identifier) ที่คุณใช้ invoke skill
- description — คำอธิบายสั้นๆ บรรทัดเดียวที่ agent ใช้ตัดสินใจว่า skill นี้เกี่ยวข้องเมื่อใด
- argument-hint — บอกผู้ใช้ว่าต้องระบุ input อะไร (ในที่นี้คือ controller หรือ route)
The Skill Definition
นี่คือ skill แบบเต็มรูปแบบ มันจะสั่งให้ agent ทำหน้าที่เป็น SDET ด้าน security และสร้าง integration tests เพื่อป้องกัน OWASP Top 10 — ไม่ใช่แค่ unit tests ธรรมดา
---
name: owasp-playspec-tester
description: "Generates Scala Play Framework security tests using
PlaySpec and FakeRequest based on OWASP Top 10 vulnerabilities."
argument-hint: "Specify the target Play controller or endpoint route
to generate tests for."
---
# OWASP Play Framework Security Tester
You are an expert Security Software Development Engineer in Test (SDET).
Your task is to generate automated security integration tests for Play
Framework applications using PlaySpec, FakeRequest, and ScalaTest.
## Instructions
When the user provides a controller, model, or route, generate a
PlaySpec test class that verifies the application's resilience against
OWASP Top 10 2025 vulnerabilities.
The Test Coverage It Enforces
หัวใจสำคัญของ skill นี้คือ checklist ของ attack classes โดยทุกๆ suite ที่ถูกสร้างขึ้นจะต้องครอบคลุมทั้ง 4 อย่างนี้ เพื่อไม่ให้มีอะไรถูกข้ามไปอย่างเงียบๆ:
-
Injection (SQL/NoSQL/Command) — ส่ง payloads อย่างเช่น
' OR 1=1 -- และ ตรวจสอบว่า response ที่ได้คือ400 BAD_REQUEST หรือ401 UNAUTHORIZED , โดยต้องไม่เป็น500 INTERNAL_SERVER_ERROR ที่อาจทำให้ข้อมูลรั่วไหล -
Cross-Site Scripting (XSS) — inject ค่าอย่าง
<script>alert(1)</script> เข้าไปใน JSON หรือ form bodies และตรวจสอบว่า raw payload ต้องไม่ถูกสะท้อนกลับมาโดยไม่ได้ทำการ escape -
Security Misconfiguration — ตรวจสอบว่า responses มี secure headers
(
X-Frame-Options ,X-Content-Type-Options ,Content-Security-Policy ) -
Broken Access Control — ยิงไปยัง restricted endpoints โดยไม่มี session หรือ JWT ที่ถูกต้อง
และตรวจสอบว่าได้
401 UNAUTHORIZED หรือ403 FORBIDDEN
Code Guidelines
skill นี้ยังกำหนด วิธีการ เขียน tests ด้วย เพื่อให้ output มีความสม่ำเสมอและสามารถรันได้จริง:
- สร้าง seed test data ใน
def initial(): Unit เพื่อจำลองข้อมูลใน database - ใช้
play.api.test.FakeRequest เพื่อจำลอง malicious traffic - ใช้
play.api.test.Helpers._ สำหรับ routing และ assertions (status(result) ,contentAsString(result) ) - สร้างโค้ด Scala ที่ถูกต้องในรูปแบบของ ScalaTest BDD style:
"Endpoint" should { "reject..." in { ... } }
What the Output Looks Like
เมื่อเรียกใช้ skill นี้กับ controller มันจะสร้าง spec ที่พร้อมรันให้ทันที ตัวอย่างเช่น:
class UserControllerSecuritySpec extends PlaySpec with GuiceOneAppPerSuite {
def initial(): Unit = {
// seed a known user to attack against
}
"UserController" should {
"reject SQL injection in the login field" in {
val payload = Json.obj("username" -> "' OR 1=1 --", "password" -> "x")
val request = FakeRequest(POST, "/login").withJsonBody(payload)
val result = route(app, request).get
status(result) must (be(BAD_REQUEST) or be(UNAUTHORIZED))
status(result) mustNot be(INTERNAL_SERVER_ERROR)
}
"escape XSS payloads in the profile name" in {
val payload = Json.obj("name" -> "<script>alert(1)</script>")
val request = FakeRequest(POST, "/profile").withJsonBody(payload)
val result = route(app, request).get
contentAsString(result) mustNot include("<script>")
}
"return secure headers on the home page" in {
val result = route(app, FakeRequest(GET, "/")).get
header("X-Frame-Options", result) mustBe defined
header("X-Content-Type-Options", result) mustBe defined
header("Content-Security-Policy", result) mustBe defined
}
"block access to admin without a token" in {
val result = route(app, FakeRequest(GET, "/admin")).get
status(result) must (be(UNAUTHORIZED) or be(FORBIDDEN))
}
}
}
Why Capture It as a Skill
- ✅ Consistency — ทุก endpoint จะได้รับการทดสอบด้วย attack classes ทั้งสี่แบบเหมือนกันทุกครั้ง
- ✅ Speed — ไม่ต้องมานั่งอธิบาย requirements ใหม่ในทุกๆ controller
- ✅ Shared standard — ทั้งทีมจะ invoke มาตรฐาน security baseline แบบเดียวกัน
- ✅ Living documentation — ไฟล์ skill ก็คือ security testing policy ของคุณนั่นเอง
Bottom Line
Security testing ไม่จำเป็นต้องเป็นงานที่ทุกคนอยากจะหลีกเลี่ยงเสมอไป ด้วยการเปลี่ยน OWASP Top 10 ให้อยู่ในรูปแบบของ skill เล็กๆ ที่สามารถนำมาใช้ซ้ำได้ คุณกำลังเปลี่ยนงานที่น่าเบื่อให้กลายเป็น command แค่บรรทัดเดียว — และทำให้ คำถามที่ว่า "เราทดสอบ injection หรือยัง?" เป็นคำถามที่มีคำตอบที่เชื่อถือได้อย่างแท้จริง
Generated tests เป็นเพียงจุดเริ่มต้น ไม่ใช่การรับประกันที่สมบูรณ์ ควรทำการ review ควบคู่ไปกับการทำ manual security review สำหรับ endpoints ที่มีความเสี่ยงสูงเสมอ
通过 AI Skill 自动执行安全测试
核心结论 (BLUF): 您可以构建一个可重用的 Claude Code skill,使用 PlaySpec 和 FakeRequest 自动生成针对 OWASP Top 10 的安全测试。这确保了 Play Framework 控制器的一致性安全测试。
编写 security tests 是一项繁琐、重复且在接近 deadline 时很容易被跳过的工作。 但这正是 AI assistant 擅长的工作类型——具有明确模式,并在许多 endpoints 中重复出现。 你可以将这种知识作为 skill 记录一次并永远重复使用,而不是每次都向 Claude 提出相同的要求。
本文将介绍一个自定义的 Claude Code skill,它能使用
What is a Skill?
skill 是你提供给 AI agent 的可重用的指令集。它是一个 Markdown 文件,包含一个小的 frontmatter header 和一段指令正文。 当你 invoke 它时,agent 会将这些指令作为 expert context 加载——因此它的表现就像一个专家而不是通才。
frontmatter 有三个有用的字段:
- name — 你用来 invoke 该 skill 的 identifier。
- description — 一行摘要,agent 用它来决定该 skill 何时相关。
- argument-hint — 告诉用户需要提供什么 input(在这里是 controller 或 route)。
The Skill Definition
以下是完整的 skill。它告诉 agent 充当专注于安全性的 SDET,并生成针对 OWASP Top 10 的 integration tests,而不是普通的 unit tests。
---
name: owasp-playspec-tester
description: "Generates Scala Play Framework security tests using
PlaySpec and FakeRequest based on OWASP Top 10 vulnerabilities."
argument-hint: "Specify the target Play controller or endpoint route
to generate tests for."
---
# OWASP Play Framework Security Tester
You are an expert Security Software Development Engineer in Test (SDET).
Your task is to generate automated security integration tests for Play
Framework applications using PlaySpec, FakeRequest, and ScalaTest.
## Instructions
When the user provides a controller, model, or route, generate a
PlaySpec test class that verifies the application's resilience against
OWASP Top 10 2025 vulnerabilities.
The Test Coverage It Enforces
该 skill 的核心是一个 attack classes 清单。每个生成的 suite 必须涵盖所有四个类别,这样就不会有任何内容被悄悄跳过:
-
Injection (SQL/NoSQL/Command) — 发送类似
' OR 1=1 -- 的 payloads,并 断言 response 为400 BAD_REQUEST 或401 UNAUTHORIZED , 绝不返回可能泄露信息的500 INTERNAL_SERVER_ERROR 。 -
Cross-Site Scripting (XSS) — 将
<script>alert(1)</script> inject 到 JSON 或 form bodies 中,并断言原始 payload 不会被未经 escape 原样反射回来。 -
Security Misconfiguration — 检查 responses 是否带有 secure headers
(
X-Frame-Options ,X-Content-Type-Options ,Content-Security-Policy )。 -
Broken Access Control — 在没有有效 session 或 JWT 的情况下访问 restricted endpoints,并
断言返回
401 UNAUTHORIZED 或403 FORBIDDEN 。
Code Guidelines
该 skill 还规定了 如何 编写 tests,因此 output 是一致且可运行的:
- 在
def initial(): Unit 中生成 seed test data,以模拟 database 中的记录。 - 使用
play.api.test.FakeRequest 模拟恶意流量。 - 使用
play.api.test.Helpers._ 进行 routing 和 assertions (status(result) ,contentAsString(result) )。 - 以 ScalaTest BDD style 生成有效的 Scala 代码:
"Endpoint" should { "reject..." in { ... } } 。
What the Output Looks Like
将该 skill 指向一个 controller,它就会生成一个随时可运行的 spec。一个简化的示例:
class UserControllerSecuritySpec extends PlaySpec with GuiceOneAppPerSuite {
def initial(): Unit = {
// seed a known user to attack against
}
"UserController" should {
"reject SQL injection in the login field" in {
val payload = Json.obj("username" -> "' OR 1=1 --", "password" -> "x")
val request = FakeRequest(POST, "/login").withJsonBody(payload)
val result = route(app, request).get
status(result) must (be(BAD_REQUEST) or be(UNAUTHORIZED))
status(result) mustNot be(INTERNAL_SERVER_ERROR)
}
"escape XSS payloads in the profile name" in {
val payload = Json.obj("name" -> "<script>alert(1)</script>")
val request = FakeRequest(POST, "/profile").withJsonBody(payload)
val result = route(app, request).get
contentAsString(result) mustNot include("<script>")
}
"return secure headers on the home page" in {
val result = route(app, FakeRequest(GET, "/")).get
header("X-Frame-Options", result) mustBe defined
header("X-Content-Type-Options", result) mustBe defined
header("Content-Security-Policy", result) mustBe defined
}
"block access to admin without a token" in {
val result = route(app, FakeRequest(GET, "/admin")).get
status(result) must (be(UNAUTHORIZED) or be(FORBIDDEN))
}
}
}
Why Capture It as a Skill
- ✅ Consistency — 每次每个 endpoint 都会获得相同的四种 attack classes。
- ✅ Speed — 无需在每个新的 controller 上重新解释 requirements。
- ✅ Shared standard — 整个团队 invoke 相同的 security baseline。
- ✅ Living documentation — skill 文件就是你的 security testing policy。
Bottom Line
Security testing 不必是每个人都想逃避的任务。通过将 OWASP Top 10 编码为一个小的、可重用的 skill,你将繁琐的工作变成了一行命令——并使 “我们测试过 injection 了吗?”这个问题有了一个可靠的答案。
生成的 tests 只是一个起点,而不是完美保证。始终应对它们进行 review,并与针对高风险 endpoints 的 manual security review 相结合。
AI Skill でセキュリティテストを自動化する
要点 (BLUF): PlaySpec と FakeRequest を使用して OWASP Top 10 のセキュリティテストを自動生成する、再利用可能な Claude Code skill を構築できます。これにより、Play Framework コントローラーのセキュリティテストの一貫性が保たれます。
security tests の作成は退屈で反復的であり、deadline が近いと簡単にスキップされがちです。 しかし、これこそがまさに AI assistant が得意とする仕事です — 明確なパターンがあり、 多くの endpoints にわたって繰り返されます。Claude に毎回同じことを頼むのではなく、 その知識を一度 skill として取り込み、永遠に再利用することができます。
この記事では、
What is a Skill?
skill とは、AI agent に与える再利用可能な指示セットのことです。これは、小さな frontmatter header と指示の本文を含む Markdown ファイルです。 それを invoke すると、agent はそれらの指示を expert context として読み込みます — そのため、汎用的なものではなく、専門家のように振る舞います。
frontmatter には3つの便利なフィールドがあります:
- name — skill を invoke するための identifier。
- description — agent がその skill がいつ関連するかを判断するために使用する1行の要約。
- argument-hint — ユーザーにどのような input を提供すべきか(ここでは controller または route)を伝えます。
The Skill Definition
これが完全な skill です。これは、一般的な unit tests ではなく、OWASP Top 10 に対する integration tests を生成する、セキュリティに特化した SDET として機能するよう agent に指示します。
---
name: owasp-playspec-tester
description: "Generates Scala Play Framework security tests using
PlaySpec and FakeRequest based on OWASP Top 10 vulnerabilities."
argument-hint: "Specify the target Play controller or endpoint route
to generate tests for."
---
# OWASP Play Framework Security Tester
You are an expert Security Software Development Engineer in Test (SDET).
Your task is to generate automated security integration tests for Play
Framework applications using PlaySpec, FakeRequest, and ScalaTest.
## Instructions
When the user provides a controller, model, or route, generate a
PlaySpec test class that verifies the application's resilience against
OWASP Top 10 2025 vulnerabilities.
The Test Coverage It Enforces
この skill の核心は、attack classes のチェックリストです。生成されたすべての suite は、何も静かにスキップされないように、これら4つすべてをカバーする必要があります:
-
Injection (SQL/NoSQL/Command) —
' OR 1=1 -- のような payloads を送信し、 response が400 BAD_REQUEST または401 UNAUTHORIZED であることをアサートします。 決して情報の漏洩に繋がる500 INTERNAL_SERVER_ERROR であってはなりません。 -
Cross-Site Scripting (XSS) —
<script>alert(1)</script> を JSON または form bodies に inject し、 元の payload が escape されずにそのまま反射されないことをアサートします。 -
Security Misconfiguration — responses が secure headers (
X-Frame-Options ,X-Content-Type-Options ,Content-Security-Policy ) を含んでいるかをチェックします。 -
Broken Access Control — 有効な session や JWT なしで restricted endpoints にアクセスし、
401 UNAUTHORIZED または403 FORBIDDEN をアサートします。
Code Guidelines
この skill はまた、tests が どのように 書かれるべきかをも定義しているため、output は一貫しており実行可能です:
- database のレコードをシミュレートするために、
def initial(): Unit 内に seed test data を設定します。 - 悪意のあるトラフィックをシミュレートするために
play.api.test.FakeRequest を使用します。 - routing と assertions (
status(result) ,contentAsString(result) ) のためにplay.api.test.Helpers._ を使用します。 - ScalaTest BDD style で有効な Scala コードを生成します:
"Endpoint" should { "reject..." in { ... } } 。
What the Output Looks Like
この skill を controller に向けると、すぐに実行可能な spec が生成されます。以下は簡略化された例です:
class UserControllerSecuritySpec extends PlaySpec with GuiceOneAppPerSuite {
def initial(): Unit = {
// seed a known user to attack against
}
"UserController" should {
"reject SQL injection in the login field" in {
val payload = Json.obj("username" -> "' OR 1=1 --", "password" -> "x")
val request = FakeRequest(POST, "/login").withJsonBody(payload)
val result = route(app, request).get
status(result) must (be(BAD_REQUEST) or be(UNAUTHORIZED))
status(result) mustNot be(INTERNAL_SERVER_ERROR)
}
"escape XSS payloads in the profile name" in {
val payload = Json.obj("name" -> "<script>alert(1)</script>")
val request = FakeRequest(POST, "/profile").withJsonBody(payload)
val result = route(app, request).get
contentAsString(result) mustNot include("<script>")
}
"return secure headers on the home page" in {
val result = route(app, FakeRequest(GET, "/")).get
header("X-Frame-Options", result) mustBe defined
header("X-Content-Type-Options", result) mustBe defined
header("Content-Security-Policy", result) mustBe defined
}
"block access to admin without a token" in {
val result = route(app, FakeRequest(GET, "/admin")).get
status(result) must (be(UNAUTHORIZED) or be(FORBIDDEN))
}
}
}
Why Capture It as a Skill
- ✅ Consistency — すべての endpoint が常に同じ4つの attack classes でテストされます。
- ✅ Speed — 新しい controller のたびに requirements を再度説明する必要がありません。
- ✅ Shared standard — チーム全体が同じ security baseline を invoke します。
- ✅ Living documentation — skill ファイル自体が、あなたの security testing policy そのものになります。
Bottom Line
Security testing は、誰もが避けたがる作業である必要はありません。OWASP Top 10 を 再利用可能な小さな skill にエンコードすることで、面倒な作業を1行のコマンドに変えることができます。 そして、「injection のテストはしたか?」という質問に、信頼できる答えを出せるようにします。
生成された tests は出発点であり、完璧な保証ではありません。常にそれらを review し、高リスクな endpoints については manual security review と組み合わせてください。
Automatisieren Sie Sicherheitstests mit einem AI Skill
Zusammenfassung (BLUF): Sie können einen wiederverwendbaren Claude Code skill erstellen, um mithilfe von PlaySpec und FakeRequest automatisch OWASP Top 10-Sicherheitstests zu generieren. Dies gewährleistet konsistente Sicherheitstests für Ihre Play Framework-Controller.
Das Schreiben von security tests ist mühsam, repetitiv und wird leicht übersprungen, wenn eine deadline näher rückt. Aber es ist auch genau die Art von Arbeit, in der ein AI assistant gut ist — klar definierte Muster, die über viele endpoints hinweg wiederholt werden. Anstatt Claude jedes Mal dasselbe zu fragen, können Sie dieses Wissen einmal als skill erfassen und für immer wiederverwenden.
Dieser Beitrag zeigt einen benutzerdefinierten Claude Code skill, der jeden Play Framework controller
mithilfe von
What is a Skill?
Ein skill ist ein wiederverwendbares Anweisungsset, das Sie einem AI agent geben. Es ist eine Markdown-Datei mit einem kleinen frontmatter header und einem Anweisungsteil. Wenn Sie es invoke, lädt der agent diese Anweisungen als expert context — so verhält er sich wie ein Spezialist anstelle eines Generalisten.
Der frontmatter hat drei nützliche Felder:
- name — der identifier, mit dem Sie den skill invoke.
- description — eine einzeilige Zusammenfassung, die der agent verwendet, um zu entscheiden, wann der skill relevant ist.
- argument-hint — sagt dem Benutzer, welcher input bereitzustellen ist (hier ein controller oder eine route).
The Skill Definition
Hier ist der vollständige skill. Er weist den agent an, als sicherheitsorientierter SDET zu agieren und integration tests gegen die OWASP Top 10 zu generieren — keine generischen unit tests.
---
name: owasp-playspec-tester
description: "Generates Scala Play Framework security tests using
PlaySpec and FakeRequest based on OWASP Top 10 vulnerabilities."
argument-hint: "Specify the target Play controller or endpoint route
to generate tests for."
---
# OWASP Play Framework Security Tester
You are an expert Security Software Development Engineer in Test (SDET).
Your task is to generate automated security integration tests for Play
Framework applications using PlaySpec, FakeRequest, and ScalaTest.
## Instructions
When the user provides a controller, model, or route, generate a
PlaySpec test class that verifies the application's resilience against
OWASP Top 10 2025 vulnerabilities.
The Test Coverage It Enforces
Das Herzstück des skills ist eine Checkliste von attack classes. Jede generierte suite muss alle vier abdecken, sodass nichts stillschweigend übersprungen wird:
-
Injection (SQL/NoSQL/Command) — sendet payloads wie
' OR 1=1 -- und stellt sicher, dass die response400 BAD_REQUEST oder401 UNAUTHORIZED ist, und niemals ein undichter500 INTERNAL_SERVER_ERROR . -
Cross-Site Scripting (XSS) — injects
<script>alert(1)</script> in JSON oder form bodies und stellt sicher, dass der ursprüngliche payload nicht un-escaped zurückgeworfen wird. -
Security Misconfiguration — prüft, ob responses secure headers
(
X-Frame-Options ,X-Content-Type-Options ,Content-Security-Policy ) enthalten. -
Broken Access Control — greift auf restricted endpoints ohne gültige session oder JWT zu
und stellt sicher, dass ein
401 UNAUTHORIZED oder403 FORBIDDEN erfolgt.
Code Guidelines
Der skill legt auch fest, wie die tests geschrieben werden, sodass der output konsistent und ausführbar ist:
- Generieren Sie seed test data in einer
def initial(): Unit , um Datensätze in der database zu simulieren. - Verwenden Sie
play.api.test.FakeRequest , um bösartigen Traffic zu simulieren. - Verwenden Sie
play.api.test.Helpers._ für routing und assertions (status(result) ,contentAsString(result) ). - Produzieren Sie gültiges Scala im ScalaTest BDD style:
"Endpoint" should { "reject..." in { ... } } .
What the Output Looks Like
Wenden Sie den skill auf einen controller an, und er erzeugt eine sofort ausführbare spec. Ein gekürztes Beispiel:
class UserControllerSecuritySpec extends PlaySpec with GuiceOneAppPerSuite {
def initial(): Unit = {
// seed a known user to attack against
}
"UserController" should {
"reject SQL injection in the login field" in {
val payload = Json.obj("username" -> "' OR 1=1 --", "password" -> "x")
val request = FakeRequest(POST, "/login").withJsonBody(payload)
val result = route(app, request).get
status(result) must (be(BAD_REQUEST) or be(UNAUTHORIZED))
status(result) mustNot be(INTERNAL_SERVER_ERROR)
}
"escape XSS payloads in the profile name" in {
val payload = Json.obj("name" -> "<script>alert(1)</script>")
val request = FakeRequest(POST, "/profile").withJsonBody(payload)
val result = route(app, request).get
contentAsString(result) mustNot include("<script>")
}
"return secure headers on the home page" in {
val result = route(app, FakeRequest(GET, "/")).get
header("X-Frame-Options", result) mustBe defined
header("X-Content-Type-Options", result) mustBe defined
header("Content-Security-Policy", result) mustBe defined
}
"block access to admin without a token" in {
val result = route(app, FakeRequest(GET, "/admin")).get
status(result) must (be(UNAUTHORIZED) or be(FORBIDDEN))
}
}
}
Why Capture It as a Skill
- ✅ Consistency — jeder endpoint erhält jedes Mal dieselben vier attack classes.
- ✅ Speed — kein erneutes Erklären der requirements für jeden neuen controller.
- ✅ Shared standard — das gesamte Team invoke dieselbe security baseline.
- ✅ Living documentation — die skill-Datei ist Ihre security testing policy.
Bottom Line
Security testing muss nicht die Aufgabe sein, die jeder meidet. Indem Sie die OWASP Top 10 in einen kleinen, wiederverwendbaren skill codieren, verwandeln Sie eine lästige Pflicht in einen einzeiligen Befehl — und machen die Frage "Haben wir auf injection getestet?" zu einer Frage mit einer zuverlässigen Antwort.
Generierte tests sind ein Ausgangspunkt, keine Garantie. Unterziehen Sie diese immer einem review und kombinieren Sie sie mit einem manual security review für riskante endpoints.
© peerapat.cc