-
Notifications
You must be signed in to change notification settings - Fork 121
Add a global flag to customize the User-Agent #152
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: main
Are you sure you want to change the base?
Conversation
Allow specifying a custom user agent via the global flag --user-agent (-U). If no value is provided, the application falls back to the default user agent.
WalkthroughAdds a configurable User-Agent option to global config and updates HTTP request creation to use it when set, otherwise falling back to the existing default. No other request construction behavior is changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant REST as REST Client
participant Cfg as Config
participant HTTP as http.Request
Caller->>REST: NewRequest(method, url, body)
REST->>Cfg: UserAgent.Value()
alt Non-empty UserAgent
REST->>HTTP: Set header "User-Agent" = Cfg value
else Empty UserAgent
REST->>HTTP: Set header "User-Agent" = constants.UserAgent()
end
REST->>HTTP: Set query/body/Content-Type/Accept (unchanged)
REST-->>Caller: *http.Request
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
client/rest/http.go (1)
131-137: LGTM! Consider adding input validation for User-Agent strings.The type assertion and fallback logic are implemented correctly. The code safely checks if the config value is a non-empty string before using it, falling back to the default User-Agent otherwise.
However, consider adding basic validation to ensure the User-Agent string doesn't contain characters that could cause issues with HTTP headers (e.g., newlines, control characters). While
http.Header.Setdoesn't return errors, malformed headers could potentially cause unexpected behavior with certain servers or proxies.Example validation:
// set azurehound as user-agent, use custom if set in config ua := config.UserAgent.Value() if s, ok := ua.(string); ok && s != "" { // Basic validation: reject if contains control characters if strings.ContainsAny(s, "\r\n\x00") { return nil, fmt.Errorf("invalid User-Agent: contains control characters") } req.Header.Set("User-Agent", s) } else { req.Header.Set("User-Agent", constants.UserAgent()) }config/config.go (1)
358-364: LGTM! Consider enhancing the usage documentation.The config definition follows the established pattern and correctly sets all required fields. The empty default ensures the fallback behavior works as intended.
The usage text could be more descriptive to help users understand when and why they might want to customize the User-Agent (e.g., for evasion, debugging, or organizational identification purposes).
Example enhanced usage:
UserAgent = Config{ Name: "user-agent", Shorthand: "U", - Usage: "Custom User-Agent header", + Usage: "Custom User-Agent header for HTTP requests (useful for evasion, debugging, or identification)", Persistent: true, Default: "", }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client/rest/http.go(1 hunks)config/config.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
client/rest/http.go (1)
config/config.go (1)
UserAgent(358-364)
config/config.go (1)
config/internal/config.go (1)
Config(32-41)
🔇 Additional comments (2)
config/config.go (2)
375-375: LGTM!The UserAgent config is correctly added to the GlobalConfig slice, making it available as a persistent global flag across all commands.
358-364: Shorthand “U” is unique – no other occurrences found in config definitions or command flags.
|
I had the same need as #135 |
Motivation
Previously, the User-Agent used by AzureHound was hardcoded and could only be changed by recompiling the binary.
This PR introduces a simple way to set a custom User-Agent at runtime using the --user-agent (-U) flag, making it easier for evasion or for debugging/identification purposes.
Main changes
Results
Summary by CodeRabbit