Skip to content

Add katana input#7545

Open
Mzack9999 wants to merge 1 commit into
devfrom
feat/katana-input-format
Open

Add katana input#7545
Mzack9999 wants to merge 1 commit into
devfrom
feat/katana-input-format

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Parse katana JSONL crawl output as nuclei input for DAST scanning. Closes #7548.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

The PR adds a Katana JSONL input format that parses crawl records and bare URLs into request responses, registers the format with the HTTP provider, and documents and tests raw-request preservation, request synthesis, tolerant parsing, and callback termination.

Katana JSONL input

Layer / File(s) Summary
Katana parsing and request conversion
pkg/input/formats/katana/katana.go
Parses Katana JSONL and absolute URLs, converts captured or structured requests, skips invalid records, and supports early callback termination.
HTTP provider registration
pkg/input/provider/http/multiformat.go
Registers the Katana format for HTTP input selection and supported-format reporting.
Fixtures, tests, and documentation
pkg/input/formats/katana/katana_test.go, pkg/input/formats/testdata/katana.jsonl, pkg/input/formats/README.md
Adds Katana fixtures, parser coverage, and documentation for supported input and tolerance behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant KatanaJSONL
  participant KatanaFormat
  participant RequestResponse
  participant ParseCallback
  KatanaJSONL->>KatanaFormat: Provide crawl record or bare URL
  KatanaFormat->>RequestResponse: Parse raw request or synthesize and reparse
  RequestResponse->>ParseCallback: Emit parsed request response
  ParseCallback-->>KatanaFormat: Continue or stop parsing
Loading

Poem

A rabbit hops through JSON lines,
Turns crawled paths to fuzzing signs.
Raw requests stay, new ones grow,
Bad lines skip, clean streams flow.
“Katana,” twitches one bright ear—
Four requests made it here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding Katana input support, though it is somewhat broad.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/katana-input-format

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/input/formats/katana/katana_test.go (1)

20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer require.NoError for idiomatic error checking.

For asserting that an error is nil in testify/require, it is more idiomatic to use require.NoError. It will automatically format the error message alongside your custom message, matching your usage on line 28.

♻️ Proposed refactor
-	require.Nilf(t, err, "error opening katana input file: %v", err)
+	require.NoError(t, err, "error opening katana input file")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/input/formats/katana/katana_test.go` at line 20, Replace the require.Nilf
assertion in the Katana input test with require.NoError, preserving the existing
custom context message and error value.
pkg/input/formats/katana/katana.go (1)

158-172: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Dynamically add a Content-Length header if it's missing.

If body != "" but the original Katana headers do not include a Content-Length or Transfer-Encoding header, types.ParseRawRequestWithURL (which relies on standard http.ReadRequest logic) may fail to read the body and silently truncate it. It's safer to synthesize the Content-Length dynamically if it wasn't provided in the captured headers.

♻️ Proposed refactor to ensure body sizing is present
 	// Emit headers in a deterministic order, skipping Host (already written).
+	var hasBodySizing bool
 	for _, key := range sortedHeaderKeys(headers) {
 		if strings.EqualFold(key, "Host") {
 			continue
 		}
+		if strings.EqualFold(key, "Content-Length") || strings.EqualFold(key, "Transfer-Encoding") {
+			hasBodySizing = true
+		}
 		sb.WriteString(key)
 		sb.WriteString(": ")
 		sb.WriteString(headers[key])
 		sb.WriteString("\r\n")
 	}
+	if body != "" && !hasBodySizing {
+		sb.WriteString(fmt.Sprintf("Content-Length: %d\r\n", len(body)))
+	}
 	sb.WriteString("\r\n")
 	if body != "" {
 		sb.WriteString(body)
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/input/formats/katana/katana.go` around lines 158 - 172, Update the raw
request serialization around the header-emission loop to add a Content-Length
header when body is non-empty and the original headers contain neither
Content-Length nor Transfer-Encoding. Compute the length from the serialized
body using the appropriate byte length, while preserving existing headers and
avoiding duplicate Content-Length values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/input/formats/katana/katana.go`:
- Around line 48-54: Update the Headers field in katanaRequest to use
map[string][]string, matching Katana’s JSONL request.headers shape so valid
entries unmarshal correctly. Keep Body and Raw as plain string fields without
adding base64 handling.

---

Nitpick comments:
In `@pkg/input/formats/katana/katana_test.go`:
- Line 20: Replace the require.Nilf assertion in the Katana input test with
require.NoError, preserving the existing custom context message and error value.

In `@pkg/input/formats/katana/katana.go`:
- Around line 158-172: Update the raw request serialization around the
header-emission loop to add a Content-Length header when body is non-empty and
the original headers contain neither Content-Length nor Transfer-Encoding.
Compute the length from the serialized body using the appropriate byte length,
while preserving existing headers and avoiding duplicate Content-Length values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2e344b4-276e-47a6-8bc4-565e83572d12

📥 Commits

Reviewing files that changed from the base of the PR and between bcd5807 and e1a30dc.

📒 Files selected for processing (5)
  • pkg/input/formats/README.md
  • pkg/input/formats/katana/katana.go
  • pkg/input/formats/katana/katana_test.go
  • pkg/input/formats/testdata/katana.jsonl
  • pkg/input/provider/http/multiformat.go

Comment on lines +48 to +54
type katanaRequest struct {
Method string `json:"method"`
Endpoint string `json:"endpoint"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
Raw string `json:"raw"`
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does ProjectDiscovery Katana export headers as map[string]string or map[string][]string in its JSONL output, and does it base64-encode the raw and body fields?

💡 Result:

In Katana's JSONL output, the headers field is represented as a map[string][]string [1]. Regarding the raw and body fields, they are not base64-encoded by default in the standard JSONL output; they are typically represented as plain strings [1][2][3]. However, Katana provides specific flags for handling these fields. While there is an issue referencing an -irrb (-include-response-base64) flag [4], standard usage generally relies on the --omit-raw and --omit-body flags to manage or exclude this data from the output [2][5][6]. The raw and body fields contain the request/response data as captured during the crawl [1][5].

Citations:


🏁 Script executed:

sed -n '1,180p' pkg/input/formats/katana/katana.go

Repository: projectdiscovery/nuclei

Length of output: 5752


🌐 Web query:

ProjectDiscovery Katana JSONL navigation.Request headers map[string][]string raw body plain string source

💡 Result:

ProjectDiscovery Katana provides structured output in JSONL format, which includes request and response details [1][2]. The navigation.Request object (often represented as a "request" field in the JSONL output) contains information about the HTTP request, including headers and the body [3]. Key details regarding your request: 1. Request Headers: These are represented as a map[string][]string within the navigation.Request structure [3]. When exported to JSONL, they appear as a JSON object where each key is a header name and the value is an array of strings [1][4]. 2. Raw Body: The body is typically included as a plain string field [1][2]. 3. Customization: Katana allows you to omit the raw request/response data or the body entirely from the JSONL output using the -or (--omit-raw) and -ob (--omit-body) flags, respectively [2][4]. This is useful for reducing the size of the generated output file [5]. 4. Field Inspection: You can list all available fields that can be included or excluded from the JSONL output by using the -lof (--list-output-fields) flag [6][7][2]. You can subsequently exclude specific fields from the output using the -eof (--exclude-output-fields) flag [7][2]. For detailed usage, you can run katana -lof to see the full schema of available fields [7][8].

Citations:


pkg/input/formats/katana/katana.go:48-54 — Match katanaRequest.Headers to Katana's JSONL shape
Katana emits request.headers as map[string][]string, so this map[string]string field will fail to unmarshal and skip valid entries. Body and Raw are plain strings; no base64 handling is needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/input/formats/katana/katana.go` around lines 48 - 54, Update the Headers
field in katanaRequest to use map[string][]string, matching Katana’s JSONL
request.headers shape so valid entries unmarshal correctly. Keep Body and Raw as
plain string fields without adding base64 handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add katana input

1 participant