-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Enhance contributing documentation with module structure templates and guidelines #21755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dwelch-r7
wants to merge
4
commits into
rapid7:master
Choose a base branch
from
dwelch-r7:updates-agents-contributing-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a066160
Enhance contributing documentation with module structure templates an…
dwelch-r7 879de1c
Update contributing documentation for error handling and test data ge…
dwelch-r7 e0a9207
Refactor contributing documentation for agents: clarify stability, si…
dwelch-r7 f1e8c95
Update contributing documentation for agents: clarify Notes hash requ…
dwelch-r7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # Copilot Instructions | ||
|
|
||
| Refer to [AGENTS.md](../AGENTS.md) in the repository root for all project conventions, coding standards, and AI agent guidelines. | ||
|
|
||
| Path-scoped instructions in `.github/instructions/` provide file-type-specific guidance for modules, library code, tests, and documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| applyTo: "documentation/**/*.md" | ||
| --- | ||
|
|
||
| # Module Documentation Instructions | ||
|
|
||
| ## Template | ||
|
|
||
| Follow `documentation/modules/module_doc_template.md` for structure. | ||
|
|
||
| ## Required Sections | ||
|
|
||
| 1. **Introduction** — what the module does, what vulnerability it exploits | ||
| 2. **Vulnerable Application** — affected versions, fixed version, setup instructions | ||
| 3. **Verification Steps** — numbered steps to reproduce/verify | ||
| 4. **Scenarios** — must be filled out by a human with real console output | ||
|
|
||
| ## Rules | ||
|
|
||
| - Run `ruby tools/dev/msftidy_docs.rb <file>` before submitting | ||
| - Module descriptions should only use ASCII characters | ||
| - Include the range of vulnerable versions and the fixed version when known | ||
| - Do NOT include sensitive information (real IPs, credentials, API keys) | ||
| - Local/private IPs are acceptable in scenario examples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| applyTo: "lib/**/*.rb" | ||
| --- | ||
|
|
||
| # Library Code Instructions | ||
|
|
||
| ## Error Handling | ||
|
|
||
| - Use specific error classes: `Rex::RuntimeError`, `Rex::ConnectionError`, `Rex::TimeoutError`, `ArgumentError` | ||
| - NEVER `raise "bare string"` — makes targeted rescue impossible | ||
| - NEVER bare `rescue` — it discards the exception object, making debugging impossible | ||
| - NEVER `rescue Exception` — it catches `SignalException` and `SystemExit` (hides Ctrl-C and kill signals) | ||
| - Always: `rescue StandardError => e` or more specific | ||
| - Propagate with context: `raise Rex::ConnectionError, "Failed to connect to #{host}: #{e.message}"` | ||
|
|
||
| ## Documentation | ||
|
|
||
| - Add YARD `@param` and `@return` tags to ALL public methods | ||
| - Link to RFC/spec when implementing binary or protocol parsers | ||
| - Add `# frozen_string_literal: true` to new files | ||
|
|
||
| ## Naming | ||
|
|
||
| - Do NOT use `get_`/`set_` prefixes for accessor-style methods (use `def version` not `def get_version`) | ||
| - Method parameter names must be at least 2 characters | ||
|
|
||
| ## Patterns | ||
|
|
||
| - Use `Rex::Stopwatch.elapsed_time` for timing | ||
| - Use `Rex::MIME::Message` for MIME (not hardcoded XML) | ||
| - Use `Rex::RandomIdentifier::Generator` for random variable names (specify target language) | ||
| - Use `RubySMB` library for SMB operations | ||
|
|
||
| ## Testing | ||
|
|
||
| - ALL library changes require RSpec tests in `spec/` mirroring `lib/` structure | ||
| - Follow [Better Specs](https://www.betterspecs.org/) conventions | ||
| - Run: `bundle exec rspec spec/path/to/spec.rb` or `:42` for single example | ||
|
|
||
| ## Quality | ||
|
|
||
| - Keep PRs focused — small fixes are easier to review | ||
| - When overriding `cleanup`, always call `super` | ||
| - Hash cracking implementations require test hash in `tools/dev/hash_cracker_validator.rb` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| applyTo: "modules/**/*.rb" | ||
| --- | ||
|
|
||
| # Module Development Instructions | ||
|
|
||
| ## Structure Order | ||
|
|
||
| 1. `# frozen_string_literal: true` | ||
| 2. Header comment block | ||
| 3. `class MetasploitModule < Msf::Exploit::Remote` (or `Msf::Auxiliary`, `Msf::Post`) | ||
| 4. `Rank = ExcellentRanking` (exploits only) | ||
| 5. Protocol mixins (`include Msf::Exploit::Remote::HttpClient`, etc.) | ||
| 6. Utility mixins (`include Msf::Exploit::FileDropper`, etc.) | ||
| 7. `prepend Msf::Exploit::Remote::AutoCheck` — ALWAYS LAST | ||
| 8. `def initialize` with `update_info` | ||
| 9. `def check` (when possible) | ||
| 10. `def exploit` or `def run` | ||
|
|
||
| ## Required Metadata | ||
|
|
||
| - `'Name'` — Vendor Product Vulnerability Type | ||
| - `'Description'` — use `%q{}` for multi-line | ||
| - `'Author'` — array with role comments | ||
| - `'License'` — `MSF_LICENSE` | ||
| - `'References'` — `[['CVE', '...'], ['URL', '...']]` | ||
| - `'DisclosureDate'` — required for exploits | ||
| - `'Notes'` — required with `Stability`, `SideEffects`, `Reliability` | ||
|
|
||
| ## Notes Hash Values | ||
|
|
||
| Required for **exploits, auxiliary, and post** modules (enforced by rubocop). Not required for payloads, encoders, nops, or evasion. | ||
|
|
||
| - **Stability:** `CRASH_SAFE`, `CRASH_SERVICE_RESTARTS`, `CRASH_SERVICE_DOWN`, `CRASH_OS_RESTARTS`, `CRASH_OS_DOWN` | ||
| - **SideEffects:** `IOC_IN_LOGS`, `ARTIFACTS_ON_DISK`, `CONFIG_CHANGES`, `ACCOUNT_LOCKOUTS`, `SCREEN_EFFECTS` | ||
| - **Reliability:** `REPEATABLE_SESSION`, `FIRST_ATTEMPT_FAIL`, `UNRELIABLE_SESSION`, `EVENT_DEPENDENT` | ||
|
|
||
| Valid values with descriptions: [`lib/msf/core/constants.rb`](../../lib/msf/core/constants.rb). Platform classes: [`lib/msf/core/module/platform.rb`](../../lib/msf/core/module/platform.rb). | ||
|
|
||
| ## Payload Selection | ||
|
|
||
| - Command execution only → `ARCH_CMD` payloads | ||
| - Only HTTP outbound (curl/wget) → fetch payload | ||
| - File write possible → dropper/EXE (`Msf::Exploit::EXE`) | ||
| - Multi-step upload → `Msf::Exploit::CmdStager` (but prefer fetch when possible) | ||
|
|
||
| ## Do NOT | ||
|
|
||
| - Set `DefaultOptions => { 'PAYLOAD' => '...' }` unless platform-locked | ||
| - Use `cmd_exec` with string interpolation — use `create_process(exe, args: [])` | ||
| - Use `HttpFingerprint` — implement a proper `check` method instead | ||
| - Use `include` for AutoCheck — must be `prepend` | ||
| - Return bare `CheckCode::Safe` without a reason string | ||
| - Use `JSON.parse(res.body)` — use `res.get_json_document` | ||
| - Print `"#{ip}:#{port}"` — use `Rex::Socket.to_authority(ip, port)` | ||
|
|
||
| ## Auxiliary Modules | ||
|
|
||
| - Inherit from `Msf::Auxiliary` (not `Msf::Exploit::Remote`) | ||
| - Use `def run` (not `def exploit`) | ||
| - Use `report_service` / `report_vuln` for findings | ||
|
|
||
| ## Post Modules | ||
|
|
||
| - Inherit from `Msf::Post` | ||
| - Declare `'SessionTypes' => ['meterpreter', 'shell']` | ||
| - Use `create_process` for command execution (not `cmd_exec` with args) | ||
| - Use `Msf::OptionalSession` for modules that work with or without sessions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| applyTo: "spec/**/*_spec.rb" | ||
| --- | ||
|
|
||
| # RSpec Test Instructions | ||
|
|
||
| ## Conventions | ||
|
|
||
| - Follow [Better Specs](https://www.betterspecs.org/) | ||
| - Mirror `lib/` structure: `lib/msf/core/exploit/remote/http_client.rb` → `spec/lib/msf/core/exploit/remote/http_client_spec.rb` | ||
| - Use `described_class` instead of repeating the class name | ||
| - One expectation per example when practical | ||
| - Use `let` and `let!` for setup, `before` for side effects | ||
|
|
||
| ## Running Tests | ||
|
|
||
| - Single file: `bundle exec rspec spec/path/to/spec.rb` | ||
| - Single example: `bundle exec rspec spec/path/to/spec.rb:42` | ||
| - Full suite: `bundle exec rake spec` (slow — avoid during development) | ||
|
|
||
| ## Test Data | ||
|
|
||
| - Use TEST-NET-1 (`192.0.2.0/24`) for example IP addresses — never real IPs | ||
| - Use `Rex::Text.rand_text_alphanumeric` for random test data | ||
| - Use the `Faker` gem (e.g. `Faker::Internet.username`) for usernames/accounts | ||
|
|
||
| ## Module Specs | ||
|
|
||
| - Module functional tests live in `spec/modules/` | ||
| - Test end-to-end behaviour including `check` and `exploit`/`run` methods | ||
|
|
||
| ## What to Test | ||
|
|
||
| - Public API methods — inputs, outputs, edge cases | ||
| - Error handling paths — verify correct exception classes raised | ||
| - Protocol parsing — round-trip encode/decode | ||
| - Version comparison logic — boundary conditions |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we probe a bit deeper here as to why we need these changes specifically for copilot, when more detailed information is already in the agents.md 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked kiro and here was the response
So originally there was a 4000 char limit, I did some googling and discovered that's been removed and told kiro that so that's been put back how it was but kept the scoped files for efficiency