#24 Fix parsing of windows command line user agents

This commit is contained in:
George Shammas 2022-06-15 16:34:33 +00:00
parent 57adc03f87
commit c6824ae921
1 changed files with 22 additions and 0 deletions

22
main.go
View File

@ -245,6 +245,28 @@ func main() {
}
func isReqFromCmdLine(ua string) bool {
// Example User Agents
// curl/7.83.1
// Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.19044; en-US) PowerShell/7.2.4
// In the case of powershell, we have to look at only the last segment.
// We could fully parse the user agent, but that would create a lot of garbage.
// We simply look at the last word.
// A micro optimization would be to do the search in reverse and break on first match, but
// I find that harder to read.
lastSpaceIndex := 0
for i, c := range ua {
// Protect if the space is the very last symbol.
if i == len(ua)-1 {
break
}
if string(c) == " " {
lastSpaceIndex = i + 1
}
}
ua = ua[lastSpaceIndex:]
parts := strings.SplitN(ua, "/", 2)
switch parts[0] {
case "curl", "HTTPie", "httpie-go", "Wget", "fetch libfetch", "Go", "Go-http-client", "ddclient", "Mikrotik", "xh", "WindowsPowerShell", "PowerShell":