fix: escape file paths in GraphQL queries and add batch-size limits#275
Open
travellingsoldier85 wants to merge 1 commit intoentrius:testfrom
Open
Conversation
Fix two issues in the file content fetching functions used for
token-based PR scoring:
1. **GraphQL injection from unescaped file paths**: File paths containing
double quotes or backslashes are interpolated directly into GraphQL
query strings, breaking query syntax and causing the entire file
content fetch to fail silently. This means PRs touching files with
special characters in their paths get scored as 0.
- Add _escape_graphql_expression() helper that escapes \ and "
- Apply escaping in both fetch_file_contents_batch and
fetch_file_contents_with_base
2. **No batch-size limit for large PRs**: PRs with many files generate
a single GraphQL query with one object lookup per file. GitHub's
GraphQL API has query complexity limits, so large PRs can trigger
502 errors and lose all file contents for scoring.
- Add _MAX_FILES_PER_GRAPHQL_BATCH = 50 constant
- Split both fetch functions into batched requests
- Extract _fetch_file_contents_with_base_batch() as internal helper
Tests added for escaping correctness, batch splitting behavior,
special character handling, and edge cases (empty input, added/removed
files, failed batches).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix two issues in the file content fetching functions used for token-based PR scoring:
1. GraphQL injection from unescaped file paths
File paths containing double quotes or backslashes are interpolated directly into GraphQL query strings, breaking query syntax and causing the entire file content fetch to fail silently. This means PRs touching files with special characters in their paths get scored as 0.
Fix:
_escape_graphql_expression()helper that escapes\and"fetch_file_contents_batchandfetch_file_contents_with_base2. No batch-size limit for large PRs
PRs with many files generate a single GraphQL query with one object lookup per file. GitHub's GraphQL API has query complexity limits, so large PRs can trigger 502 errors and lose all file contents for scoring.
Fix:
_MAX_FILES_PER_GRAPHQL_BATCH = 50constantTests
Related Issues
No existing issue — discovered during code review of the scoring pipeline.
Testing