@@ -915,12 +915,34 @@ describe("isGitHubRepository", () => {
915915 expect ( isGitHubRepository ( "https://GITHUB.COM/user/repo.git" ) ) . toBe ( true )
916916 } )
917917
918+ it ( "should return true for GitHub subdomains" , ( ) => {
919+ expect ( isGitHubRepository ( "https://gist.github.com/user/repo" ) ) . toBe ( true )
920+ expect ( isGitHubRepository ( "https://api.github.com/repos/user/repo" ) ) . toBe ( true )
921+ expect ( isGitHubRepository ( "[email protected] :user/repo.git" ) ) . toBe ( true ) 922+ } )
923+
918924 it ( "should return false for non-GitHub URLs" , ( ) => {
919925 expect ( isGitHubRepository ( "https://gitlab.com/user/repo.git" ) ) . toBe ( false )
920926 expect ( isGitHubRepository ( "https://bitbucket.org/user/repo.git" ) ) . toBe ( false )
921927 expect ( isGitHubRepository ( "[email protected] :user/repo.git" ) ) . toBe ( false ) 922928 } )
923929
930+ it ( "should return false for malicious URLs with github.com in hostname" , ( ) => {
931+ // Security: These URLs have "github.com" as part of the hostname but are not GitHub
932+ expect ( isGitHubRepository ( "https://malicious-github.com/user/repo.git" ) ) . toBe ( false )
933+ expect ( isGitHubRepository ( "https://github.com.evil.com/user/repo.git" ) ) . toBe ( false )
934+ expect ( isGitHubRepository ( "https://fake-github.com/user/repo.git" ) ) . toBe ( false )
935+ expect ( isGitHubRepository ( "[email protected] :user/repo.git" ) ) . toBe ( false ) 936+ expect ( isGitHubRepository ( "ssh://[email protected] /user/repo.git" ) ) . toBe ( false ) 937+ } )
938+
939+ it ( "should return false for URLs with github.com in the path" , ( ) => {
940+ // Security: These URLs have "github.com" in the path but not as the hostname
941+ expect ( isGitHubRepository ( "https://evil.com/github.com/malicious/repo.git" ) ) . toBe ( false )
942+ expect ( isGitHubRepository ( "https://attacker.com/fake/github.com/path" ) ) . toBe ( false )
943+ expect ( isGitHubRepository ( "[email protected] :github.com/user/repo.git" ) ) . toBe ( false ) 944+ } )
945+
924946 it ( "should return false for undefined or empty URLs" , ( ) => {
925947 expect ( isGitHubRepository ( undefined ) ) . toBe ( false )
926948 expect ( isGitHubRepository ( "" ) ) . toBe ( false )
0 commit comments