Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/proxy/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func extractOwnerRepo(variables map[string]interface{}, query string) (string, s
if v, ok := variables["repo"].(string); ok && repo == "" {
repo = v
}
logGraphQL.Printf("extractOwnerRepo: from variables: owner=%q repo=%q", owner, repo)
}

// Fall back to parsing the query string
Expand All @@ -166,6 +167,7 @@ func extractOwnerRepo(variables map[string]interface{}, query string) (string, s
if m[2] != "" && repo == "" {
repo = m[2]
}
logGraphQL.Printf("extractOwnerRepo: from query regex: owner=%q repo=%q", owner, repo)
}
}

Expand All @@ -187,19 +189,34 @@ func extractOwnerRepo(variables map[string]interface{}, query string) (string, s
// searchQueryArgPattern extracts the literal query string from search(query:"...", ...)
var searchQueryArgPattern = regexp.MustCompile(`(?i)\bsearch\s*\(\s*query\s*:\s*"([^"]+)"`)

// truncateForLog truncates s to at most maxRunes runes, for safe debug logging.
func truncateForLog(s string, maxRunes int) string {
if maxRunes <= 0 {
return ""
}
r := []rune(s)
if len(r) <= maxRunes {
return s
}
return string(r[:maxRunes])
}

// extractSearchQuery returns the search query argument from a GraphQL search
// query. It checks variables ($query) first, then inline query text.
func extractSearchQuery(query string, variables map[string]interface{}) string {
// Check variables for $query
if variables != nil {
if v, ok := variables["query"].(string); ok && v != "" {
logGraphQL.Printf("extractSearchQuery: found in variables: %q", truncateForLog(v, 80))
return v
Comment on lines 209 to 211
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The search query value is user-controlled and may contain newlines/control characters; logging it with %s can create multi-line or hard-to-parse debug output. Consider quoting/escaping the truncated value (e.g., using a quoted format verb) to keep logs single-line and unambiguous.

This issue also appears on line 203 of the same file.

See below for a potential fix:

func truncateForLog(s string, maxRunes int) string {
	if maxRunes <= 0 {
		return ""
	}
	r := []rune(s)
	if len(r) <= maxRunes {
		return s
	}
	return string(r[:maxRunes])
}

// extractSearchQuery returns the search query argument from a GraphQL search
// query. It checks variables ($query) first, then inline query text.
func extractSearchQuery(query string, variables map[string]interface{}) string {
	// Check variables for $query
	if variables != nil {
		if v, ok := variables["query"].(string); ok && v != "" {
			logGraphQL.Printf("extractSearchQuery: found in variables: %q", truncateForLog(v, 80))
			return v
		}
	}
	// Parse inline: search(query:"repo:owner/name is:issue", ...)
	if m := searchQueryArgPattern.FindStringSubmatch(query); m != nil {
		logGraphQL.Printf("extractSearchQuery: found inline: %q", truncateForLog(m[1], 80))

Copilot uses AI. Check for mistakes.
}
}
// Parse inline: search(query:"repo:owner/name is:issue", ...)
if m := searchQueryArgPattern.FindStringSubmatch(query); m != nil {
logGraphQL.Printf("extractSearchQuery: found inline: %q", truncateForLog(m[1], 80))
return m[1]
}
logGraphQL.Print("extractSearchQuery: no search query found")
return ""
}

Expand Down
Loading