Skip to content
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

fix secrets lookup logic #6059

Merged
merged 2 commits into from
Feb 20, 2025
Merged

fix secrets lookup logic #6059

merged 2 commits into from
Feb 20, 2025

Conversation

dogancanbakir
Copy link
Member

@dogancanbakir dogancanbakir commented Feb 19, 2025

Proposed changes

Closes #5498

$ cat secrets.yaml 
static:
  - type: cookie
    domains-regex:
      - php.vulnerabletarget.com
    cookies:
      - key: SESSIONID
        value: f9a9a185-1e05-41c7-98f3-432de6b114b0

  - type: header
    domains:
      - php.vulnerabletarget.com
    headers:
      - key: secretkey
        value: 33626665393961652d623633652d346639382d393366362d663532343935653336376438

  - type: cookie
    domains-regex:
      - asp.vulnerabletarget.com
    cookies:
      - key: SESSIONID
        value: c9190916-1b97-401d-a223-492894deff9e

  - type: header
    domains:
      - asp.vulnerabletarget.com
    headers:
      - key: secretkey
        value: 33343063656665352d616130352d346537622d616338322d306337346339353635326466


$ cat config.yaml
list: 'target.list'

templates:  'test_template.yaml'

prefetch-secrets: true
secret-file: 'secrets.yaml'


debug-req: true

bulk-size: 50
cloud-upload: false
concurrency: 50
disable-update-check: true
no-interactsh: true
no-max-host-error: true
rate-limit: 500
stats: true
timeout: 5
uncover: false
update-templates: false


$ go run . --config config.yaml

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.3.9

                projectdiscovery.io

[WRN] The concurrency value is higher than max-host-error
[INF] Adjusting max-host-error to the concurrency value: 50
[INF] Current nuclei version: v3.3.9 (outdated)
[INF] Current nuclei-templates version: v10.1.2 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 52
[INF] Templates loaded for current scan: 1
[WRN] Loading 1 unsigned templates for scan. Use with caution.
[INF] Targets loaded for current scan: 2
[INF] Pre-fetching secrets from authprovider[s]
[INF] [test] Dumped HTTP request for http://php.vulnerabletarget.com/api/order/plaintext

POST /api/order/plaintext HTTP/1.1
Host: php.vulnerabletarget.com
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Connection: close
Content-Length: 0
Cookie: SESSIONID=f9a9a185-1e05-41c7-98f3-432de6b114b0
Secretkey: 33626665393961652d623633652d346639382d393366362d663532343935653336376438
Accept-Encoding: gzip

[INF] [test] Dumped HTTP request for http://asp.vulnerabletarget.com/api/order/plaintext

POST /api/order/plaintext HTTP/1.1
Host: asp.vulnerabletarget.com
User-Agent: Mozilla/5.0 (Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Connection: close
Content-Length: 0
Cookie: SESSIONID=c9190916-1b97-401d-a223-492894deff9e
Secretkey: 33343063656665352d616130352d346537622d616338322d306337346339353635326466
Accept-Encoding: gzip

[INF] No results found. Better luck next time!
[0:00:01] | Templates: 1 | Hosts: 2 | RPS: 1 | Matched: 0 | Errors: 0 | Requests: 2/2 (100%)

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the authentication lookup process to now consider all applicable strategies, ensuring more comprehensive results for varied scenarios.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

The update modifies the logic in the LookupAddr method found in the file authentication provider. Instead of returning immediately upon finding the first match, the method now iterates over all possible domain and regex patterns, appending each matching strategy to a slice. At the end of the method, the full collection of matching strategies is returned, ensuring all applicable matches are provided. Additionally, the LookupAddr method in the MultiAuthProvider struct has been updated to check for non-empty results based on the length of the returned strategies.

Changes

File Summary of Changes
pkg/authprovider/file.go Modified LookupAddr to accumulate all matching authx.AuthStrategy instances rather than returning after the first match. Introduced a strategies slice to collect and return results.
pkg/authprovider/multi.go Updated LookupAddr to check if the length of returned strategy is greater than zero instead of checking for nil, altering the logic for determining valid authentication strategies.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant F as FileAuthProvider.LookupAddr
    C->>F: Call LookupAddr(addr)
    F->>F: Initialize strategies slice
    F->>F: Iterate over domain & regex patterns
    alt Match found
      F->>F: Append strategy to strategies slice
    end
    F->>C: Return strategies slice
Loading

Poem

I’m a rabbit hopping with glee,
In code fields where changes run free.
Strategies collect like carrots in a row,
Each match found helps our program grow.
With a twitch of my nose, I cheer the new flow!
🥕🐇 Happy code days, on we go!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dogancanbakir dogancanbakir self-assigned this Feb 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89c77d1 and 544d4f3.

📒 Files selected for processing (1)
  • pkg/authprovider/file.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (3)
pkg/authprovider/file.go (3)

125-126: LGTM! Good initialization for accumulating strategies.

The initialization of the strategies slice is well-placed and supports the new behavior of collecting all matching strategies.


134-138: LGTM! Correctly accumulates all matching domain strategies.

The modification to append matching domain strategies instead of returning immediately is a good improvement. The case-insensitive comparison is preserved, ensuring reliable domain matching.


139-143: LGTM! Correctly accumulates all matching regex strategies.

The modification to append matching regex strategies instead of returning immediately aligns well with the domain matching behavior, ensuring all applicable strategies are collected.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/authprovider/multi.go (1)

32-50: Consider using consistent length checks across all lookup methods.

For consistency with the updated LookupAddr method, consider updating the nil checks in LookupURL and LookupURLX to use length checks as well.

Apply these diffs to maintain consistency:

func (m *MultiAuthProvider) LookupURL(u *url.URL) []authx.AuthStrategy {
	for _, provider := range m.Providers {
		strategy := provider.LookupURL(u)
-		if strategy != nil {
+		if len(strategy) > 0 {
			return strategy
		}
	}
	return nil
}

func (m *MultiAuthProvider) LookupURLX(u *urlutil.URL) []authx.AuthStrategy {
	for _, provider := range m.Providers {
		strategy := provider.LookupURLX(u)
-		if strategy != nil {
+		if len(strategy) > 0 {
			return strategy
		}
	}
	return nil
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 544d4f3 and c9376f2.

📒 Files selected for processing (1)
  • pkg/authprovider/multi.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
pkg/authprovider/multi.go (1)
Learnt from: dogancanbakir
PR: projectdiscovery/nuclei#6059
File: pkg/authprovider/file.go:144-145
Timestamp: 2025-02-19T13:21:35.933Z
Learning: In the Nuclei project, when checking auth strategies returned from LookupAddr, use len() check instead of nil check as the function returns an empty slice for no matches.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (1)
pkg/authprovider/multi.go (1)

22-30: LGTM! The len() check is the correct approach.

The change from nil check to len() check aligns with the project's preferred way of handling empty results from LookupAddr.

@ehsandeep ehsandeep merged commit cbd90df into dev Feb 20, 2025
23 checks passed
@ehsandeep ehsandeep deleted the fix_secrets_lookup_logic branch February 20, 2025 00:31
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.

Only the last secret matching domain is used from a secret file
3 participants