Skip to content

Comments

Fix(Onyphe): Handle quoted queries correctly#693

Merged
dogancanbakir merged 4 commits intoprojectdiscovery:devfrom
JiWonOck:fix/onyphe-bug
Oct 1, 2025
Merged

Fix(Onyphe): Handle quoted queries correctly#693
dogancanbakir merged 4 commits intoprojectdiscovery:devfrom
JiWonOck:fix/onyphe-bug

Conversation

@JiWonOck
Copy link
Contributor

@JiWonOck JiWonOck commented Aug 9, 2025

What does this PR do?

This PR fixes a bug in the Onyphe search agent where queries containing double quotes (") would fail. The root cause was a line of code that incorrectly reversed the URL encoding of double quotes, stripping them from the final API request.

This change removes the faulty line, ensuring that quoted queries are correctly escaped and passed to the Onyphe API, which allows for proper exact-match searches.

Fixes #685

Changes

  • Modified sources/agent/onyphe/onyphe.go:
    • Removed the strings.ReplaceAll call that was incorrectly decoding the %22 characters back into " after they had been properly escaped by url.QueryEscape.

How to test

  1. Set up API Key: Ensure your Onyphe API key is configured in ~/.config/uncover/provider-config.yaml or a temporary provider-config.yaml file.

  2. Build the binary:

    go build ./cmd/uncover
  3. Run a test query:
    To ensure your shell passes the query to the program correctly, wrap the entire query in single quotes (').

    # Using a temporary provider config
    ./uncover -on 'issuer.commonname:"Quasar Server CA"' -j -pc provider-config.yaml
    
    # Or using the default provider config
    ./uncover -on 'issuer.commonname:"Quasar Server CA"' -j

    The command should now return results successfully.

Additional Notes

  • CLI Result De-duplication: The number of results from the CLI may differ from the Onyphe website. This is because uncover de-duplicates results based on the unique IP:Port combination.
  • Shell Interaction: The use of single quotes is crucial for preventing the shell from stripping or misinterpreting the inner double quotes required by the Onyphe query.

Summary by CodeRabbit

  • Bug Fixes
    • Improved formatting of query parameters in API requests to ensure correct handling of double-quote characters.

ehsandeep and others added 3 commits June 20, 2025 21:48
…iscovery#689)

Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.18.0 to 0.27.0.
- [Commits](golang/oauth2@v0.18.0...v0.27.0)

---
updated-dependencies:
- dependency-name: golang.org/x/oauth2
  dependency-version: 0.27.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 9, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The change updates the Onyphe agent's query URL construction logic to preserve double quotes in search queries. After URL-encoding the query, it replaces encoded double-quote sequences ("%22") with literal double-quote characters, ensuring the resulting API request URL matches the expected format for quoted queries.

Changes

Cohort / File(s) Change Summary
Onyphe Query URL Handling
sources/agent/onyphe/onyphe.go
Imports the strings package and modifies the queryURL method to replace %22 with " after URL-encoding the query, ensuring double quotes are preserved in the final URL. No other logic or control flow changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Assessment against linked issues

Objective Addressed Explanation
Preserve double quotes in Onyphe search queries so that queries like issuer.commonname:"Quasar Server CA" are encoded as %22...%22 in the URL, matching expected API behavior (#685)

Poem

A bunny hopped through code today,
To keep your quotes from hopping away.
With strings and URLs now aligned,
Your Onyphe queries will work just fine!
So search with quotes, don’t fear the night—
The bug is fixed, your queries right!
🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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 (2)
sources/agent/onyphe/onyphe.go (2)

10-10: Remove unused import "strings"

Once ReplaceAll is removed, "strings" becomes unused and will fail compilation.

 import (
 	"encoding/json"
 	"errors"
 	"fmt"
 	"io"
 	"net/http"
 	"net/url"
-	"strings"
 
 	"github.com/projectdiscovery/uncover/sources"
 )

37-63: Consider enforcing query.Limit when emitting results

Current pagination stops after counting fetched items, but individual pages are emitted in full, potentially exceeding query.Limit (page size is hardcoded to 10). Either:

  • Pass the limit/remaining to query() and only emit up to the remaining count, or
  • Make size dynamic per page (min(10, remaining)) by parameterizing URLTemplate.

If helpful, I can propose a minimal patch to thread remaining-through and cap emissions. Want me to draft it?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a159bf and 7f6d62b.

📒 Files selected for processing (1)
  • sources/agent/onyphe/onyphe.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
sources/agent/onyphe/onyphe.go (4)
sources/keys.go (1)
  • Keys (3-22)
uncover.go (1)
  • New (56-110)
sources/agent/onyphe/response.go (2)
  • Result (11-14)
  • OnypheResponse (3-9)
sources/agent.go (1)
  • Query (3-6)
🔇 Additional comments (4)
sources/agent/onyphe/onyphe.go (4)

31-33: Good: early validation of API key

Clear error on missing Onyphe API key. LGTM.


82-86: LGTM: robust JSON parsing with error propagation

Proper unmarshalling and error propagation to the results channel.


88-92: LGTM: API-level error surfaced

Checking apiResponse.Error and surfacing a clear error is good practice.


105-107: Regression: decoding %22 back to " strips quoted queries; remove ReplaceAll

After url.QueryEscape, replacing %22 with " reintroduces the original bug. Onyphe expects the quotes to remain percent-encoded so the API receives exact-match queries. Keep the encoded %22.

Apply this fix:

-	escapedQuery := url.QueryEscape(onypheRequest.Query)
-	escapedQuery = strings.ReplaceAll(escapedQuery, "%22", "\"")
+	escapedQuery := url.QueryEscape(onypheRequest.Query)

Optionally, build the URL with url.Values to avoid any future mis-encoding:

u, _ := url.Parse("https://www.onyphe.io/api/v2/search/")
q := url.Values{}
q.Set("q", onypheRequest.Query)
q.Set("page", strconv.Itoa(onypheRequest.Page))
q.Set("size", "10")
u.RawQuery = q.Encode()
urlWithQuery := u.String()

To ensure no similar decoding remains elsewhere, run:

#!/bin/bash
rg -n --fixed-strings 'strings.ReplaceAll(escapedQuery, "%22", "\"")' || true

Likely an incorrect or invalid review comment.

@Mzack9999 Mzack9999 changed the base branch from main to dev September 4, 2025 12:30
@dogancanbakir dogancanbakir merged commit 6d13e66 into projectdiscovery:dev Oct 1, 2025
9 checks passed
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.

Double quotes stripped from query, leading to incorrect Onyphe search results

4 participants