Skip to content

Commit 1dda35f

Browse files
runningcodeclaude
andcommitted
refactor: remove SHA validation from GitHub Actions PR head extraction
Remove client-side SHA validation as the backend will handle validation. This simplifies the code while maintaining the security fix from proper JSON parsing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 798db05 commit 1dda35f

1 file changed

Lines changed: 7 additions & 48 deletions

File tree

src/utils/vcs.rs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -586,20 +586,7 @@ fn extract_pr_head_sha_from_event(json_content: &str) -> Option<String> {
586586
};
587587

588588
// Extract the PR head SHA if present
589-
let sha = payload.pull_request?.head.sha;
590-
591-
// Validate that the SHA is a 40-character hexadecimal string
592-
if is_valid_git_sha(&sha) {
593-
Some(sha)
594-
} else {
595-
debug!("Invalid SHA format in GitHub event payload: {}", sha);
596-
None
597-
}
598-
}
599-
600-
/// Validates that a string is a valid Git SHA (40-character hexadecimal string)
601-
fn is_valid_git_sha(sha: &str) -> bool {
602-
sha.len() == 40 && sha.chars().all(|c| c.is_ascii_hexdigit())
589+
Some(payload.pull_request?.head.sha)
603590
}
604591

605592
/// Given commit specs, repos and remote_name this returns a list of head
@@ -1528,37 +1515,6 @@ mod tests {
15281515
std::env::remove_var("GITHUB_REF");
15291516
}
15301517

1531-
#[test]
1532-
fn test_is_valid_git_sha() {
1533-
// Test valid 40-character hex SHA (using existing SHA from real test)
1534-
assert!(is_valid_git_sha("19ef6adc4dbddf733db6e833e1f96fb056b6dba4"));
1535-
1536-
// Test valid SHA with all digits
1537-
assert!(is_valid_git_sha("1234567890123456789012345678901234567890"));
1538-
1539-
// Test valid SHA with mixed case
1540-
assert!(is_valid_git_sha("AbCdEf0123456789aBcDeF0123456789aBcDeF01"));
1541-
1542-
// Test invalid SHA - too short
1543-
assert!(!is_valid_git_sha("abc123def456"));
1544-
1545-
// Test invalid SHA - too long
1546-
assert!(!is_valid_git_sha(
1547-
"19ef6adc4dbddf733db6e833e1f96fb056b6dba4extra"
1548-
));
1549-
1550-
// Test invalid SHA - contains non-hex characters
1551-
assert!(!is_valid_git_sha(
1552-
"19ef6adc4dbddf733db6e833e1f96fb056b6dbag"
1553-
));
1554-
1555-
// Test valid SHA - all uppercase
1556-
assert!(is_valid_git_sha("19EF6ADC4DBDDF733DB6E833E1F96FB056B6DBA4"));
1557-
1558-
// Test empty string
1559-
assert!(!is_valid_git_sha(""));
1560-
}
1561-
15621518
#[test]
15631519
fn test_extract_pr_head_sha_from_event() {
15641520
// Test valid PR event JSON with valid 40-character SHA
@@ -1650,16 +1606,19 @@ mod tests {
16501606
Some("19ef6adc4dbddf733db6e833e1f96fb056b6dba5".to_owned())
16511607
);
16521608

1653-
// Test invalid SHA format is rejected
1654-
let invalid_sha_json = r#"{
1609+
// Test that any SHA format is accepted (backend will validate)
1610+
let any_sha_json = r#"{
16551611
"pull_request": {
16561612
"head": {
16571613
"sha": "invalid-sha-123"
16581614
}
16591615
}
16601616
}"#;
16611617

1662-
assert_eq!(extract_pr_head_sha_from_event(invalid_sha_json), None);
1618+
assert_eq!(
1619+
extract_pr_head_sha_from_event(any_sha_json),
1620+
Some("invalid-sha-123".to_owned())
1621+
);
16631622

16641623
// Test invalid JSON is handled gracefully
16651624
assert_eq!(extract_pr_head_sha_from_event("invalid json {"), None);

0 commit comments

Comments
 (0)