-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add security.txt detection flag #2472
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -330,6 +330,15 @@ func New(options *Options) (*Runner, error) { | |||||||||||||||||||||||||||||||||||||||||||||
| scanopts.VHostInput = options.VHostInput | ||||||||||||||||||||||||||||||||||||||||||||||
| scanopts.OutputContentType = options.OutputContentType | ||||||||||||||||||||||||||||||||||||||||||||||
| scanopts.RequestBody = options.RequestBody | ||||||||||||||||||||||||||||||||||||||||||||||
| if options.SecurityTxt { | ||||||||||||||||||||||||||||||||||||||||||||||
| options.OutputMatchString = append(options.OutputMatchString, "Contact:") | ||||||||||||||||||||||||||||||||||||||||||||||
| options.OutputMatchStatusCode = appendCommaSeparatedValue(options.OutputMatchStatusCode, "200") | ||||||||||||||||||||||||||||||||||||||||||||||
| options.RequestURIs = appendCommaSeparatedValue(options.RequestURIs, "/.well-known/security.txt,/security.txt") | ||||||||||||||||||||||||||||||||||||||||||||||
| options.JSONOutput = true | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if options.RequestURIs != "" { | ||||||||||||||||||||||||||||||||||||||||||||||
| options.requestURIs = normalizeRequestURIs(options.RequestURIs) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| scanopts.Unsafe = options.Unsafe | ||||||||||||||||||||||||||||||||||||||||||||||
| scanopts.Pipeline = options.Pipeline | ||||||||||||||||||||||||||||||||||||||||||||||
| scanopts.HTTP2Probe = options.HTTP2Probe | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2632,6 +2641,11 @@ retry: | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| securityTxt := false | ||||||||||||||||||||||||||||||||||||||||||||||
| if r.options.SecurityTxt { | ||||||||||||||||||||||||||||||||||||||||||||||
| securityTxt = isSecurityTxt(resp) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| result := Result{ | ||||||||||||||||||||||||||||||||||||||||||||||
| Timestamp: time.Now(), | ||||||||||||||||||||||||||||||||||||||||||||||
| Request: request, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2650,6 +2664,7 @@ retry: | |||||||||||||||||||||||||||||||||||||||||||||
| StatusCode: resp.StatusCode, | ||||||||||||||||||||||||||||||||||||||||||||||
| Location: resp.GetHeaderPart("Location", ";"), | ||||||||||||||||||||||||||||||||||||||||||||||
| ContentType: resp.GetHeaderPart("Content-Type", ";"), | ||||||||||||||||||||||||||||||||||||||||||||||
| SecurityTxt: securityTxt, | ||||||||||||||||||||||||||||||||||||||||||||||
| Title: title, | ||||||||||||||||||||||||||||||||||||||||||||||
| str: builder.String(), | ||||||||||||||||||||||||||||||||||||||||||||||
| VHost: isvhost, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2973,6 +2988,54 @@ func (r Result) CSVRow(scanopts *ScanOptions) string { //nolint | |||||||||||||||||||||||||||||||||||||||||||||
| return res | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // appendCommaSeparatedValue appends comma-separated values to an existing | ||||||||||||||||||||||||||||||||||||||||||||||
| // comma-separated string, handling empty inputs gracefully. | ||||||||||||||||||||||||||||||||||||||||||||||
| func appendCommaSeparatedValue(current string, values string) string { | ||||||||||||||||||||||||||||||||||||||||||||||
| current = strings.TrimSpace(current) | ||||||||||||||||||||||||||||||||||||||||||||||
| values = strings.TrimSpace(values) | ||||||||||||||||||||||||||||||||||||||||||||||
| if current == "" { | ||||||||||||||||||||||||||||||||||||||||||||||
| return values | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if values == "" { | ||||||||||||||||||||||||||||||||||||||||||||||
| return current | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return current + "," + values | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // normalizeRequestURIs splits a comma-separated URI string into a deduplicated, | ||||||||||||||||||||||||||||||||||||||||||||||
| // trimmed slice preserving first-occurrence order. | ||||||||||||||||||||||||||||||||||||||||||||||
| func normalizeRequestURIs(requestURIs string) []string { | ||||||||||||||||||||||||||||||||||||||||||||||
| items := stringsutil.SplitAny(requestURIs, ",") | ||||||||||||||||||||||||||||||||||||||||||||||
| cleaned := make([]string, 0, len(items)) | ||||||||||||||||||||||||||||||||||||||||||||||
| seen := make(map[string]struct{}, len(items)) | ||||||||||||||||||||||||||||||||||||||||||||||
| for _, item := range items { | ||||||||||||||||||||||||||||||||||||||||||||||
| item = strings.TrimSpace(item) | ||||||||||||||||||||||||||||||||||||||||||||||
| if item == "" { | ||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if _, ok := seen[item]; ok { | ||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| seen[item] = struct{}{} | ||||||||||||||||||||||||||||||||||||||||||||||
| cleaned = append(cleaned, item) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return cleaned | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // isSecurityTxt validates whether an HTTP response represents a valid security.txt | ||||||||||||||||||||||||||||||||||||||||||||||
| // file: HTTP 200, text/plain content type, and a Contact field present in the body. | ||||||||||||||||||||||||||||||||||||||||||||||
| func isSecurityTxt(resp *httpx.Response) bool { | ||||||||||||||||||||||||||||||||||||||||||||||
| if resp == nil || resp.StatusCode != 200 { | ||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| contentType := strings.ToLower(resp.GetHeaderPart("Content-Type", ";")) | ||||||||||||||||||||||||||||||||||||||||||||||
| if contentType != "" && !strings.Contains(contentType, "text/plain") { | ||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| body := string(resp.RawData) | ||||||||||||||||||||||||||||||||||||||||||||||
| return strings.Contains(body, "Contact:") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3027
to
+3037
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: RFC 9116 specifies that security.txt field names are case-insensitive. It defines the field “name” as a Citations: Case-sensitive "Contact:" check may miss valid security.txt files. Per RFC 9116, field names in security.txt are case-insensitive. The current check Suggested fix func isSecurityTxt(resp *httpx.Response) bool {
if resp == nil || resp.StatusCode != 200 {
return false
}
contentType := strings.ToLower(resp.GetHeaderPart("Content-Type", ";"))
if contentType != "" && !strings.Contains(contentType, "text/plain") {
return false
}
- body := string(resp.RawData)
- return strings.Contains(body, "Contact:")
+ body := strings.ToLower(string(resp.RawData))
+ return strings.Contains(body, "contact:")
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func (r *Runner) skipCDNPort(host string, port string) bool { | ||||||||||||||||||||||||||||||||||||||||||||||
| // if the option is not enabled we don't skip | ||||||||||||||||||||||||||||||||||||||||||||||
| if !r.scanopts.ExcludeCDN { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
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.
Critical:
OutputMatchStatusCodemodification occurs after parsing, making status code filter ineffective.When
--security-txtis enabled, this code appends"200"tooptions.OutputMatchStatusCode. However,ValidateOptions()(called beforeNew()inParseOptions()) has already parsedOutputMatchStatusCodeinto thematchStatusCodeslice used for filtering at line 1204.As a result, the
200status code match won't be enforced when using--security-txtalone, potentially returning non-200 responses.🐛 Proposed fix: Parse the status code after modification
if options.SecurityTxt { options.OutputMatchString = append(options.OutputMatchString, "Contact:") options.OutputMatchStatusCode = appendCommaSeparatedValue(options.OutputMatchStatusCode, "200") options.RequestURIs = appendCommaSeparatedValue(options.RequestURIs, "/.well-known/security.txt,/security.txt") options.JSONOutput = true + // Re-parse matchStatusCode since we modified OutputMatchStatusCode after initial parsing + if parsed, err := stringz.StringToSliceInt(options.OutputMatchStatusCode); err == nil { + options.matchStatusCode = parsed + } }📝 Committable suggestion
🤖 Prompt for AI Agents