@@ -35,14 +35,14 @@ func verifyAccessLevel(access AccessLevel) {
3535
3636var ErrAccess = errors .New ("unauthorized" )
3737
38- func checkAccessLevel (c context.Context , r * http.Request , level AccessLevel ) error {
39- if accessLevel (c , r ) >= level {
38+ func checkAccessLevel (ctx context.Context , r * http.Request , level AccessLevel ) error {
39+ if accessLevel (ctx , r ) >= level {
4040 return nil
4141 }
42- if u := user .Current (c ); u != nil {
42+ if u := user .Current (ctx ); u != nil {
4343 // Log only if user is signed in. Not-signed-in users are redirected to login page.
44- log .Errorf (c , "unauthorized access: %q [%q] access level %v, url %.100s" ,
45- u .Email , u .AuthDomain , level , getCurrentURL (c ))
44+ log .Errorf (ctx , "unauthorized access: %q [%q] access level %v, url %.100s" ,
45+ u .Email , u .AuthDomain , level , getCurrentURL (ctx ))
4646 }
4747 return ErrAccess
4848}
@@ -57,14 +57,14 @@ func isEmailAuthorized(email string, acls []*ACLItem) (bool, AccessLevel) {
5757 return false , AccessPublic
5858}
5959
60- func currentUser (c context.Context ) * user.User {
61- u := user .Current (c )
60+ func currentUser (ctx context.Context ) * user.User {
61+ u := user .Current (ctx )
6262 if u != nil {
6363 return u
6464 }
6565 // Let's ignore err here. In case of the wrong token we'll return nil here (it means AccessPublic).
6666 // Bad or expired tokens will also enable throttling and make the authorization problem visible.
67- u , _ = user .CurrentOAuth (c , "https://www.googleapis.com/auth/userinfo.email" )
67+ u , _ = user .CurrentOAuth (ctx , "https://www.googleapis.com/auth/userinfo.email" )
6868 return u
6969}
7070
@@ -75,8 +75,8 @@ func currentUser(c context.Context) *user.User {
7575//
7676// OAuth2 token is expected to be present in "Authorization" header.
7777// Example: "Authorization: Bearer $(gcloud auth print-access-token)".
78- func accessLevel (c context.Context , r * http.Request ) AccessLevel {
79- _ , al := userAccessLevel (currentUser (c ), r .FormValue ("access" ), getConfig (c ))
78+ func accessLevel (ctx context.Context , r * http.Request ) AccessLevel {
79+ _ , al := userAccessLevel (currentUser (ctx ), r .FormValue ("access" ), getConfig (ctx ))
8080 return al
8181}
8282
@@ -108,60 +108,60 @@ func userAccessLevel(u *user.User, wantAccess string, config *GlobalConfig) (boo
108108 return isEmailAuthorized (u .Email , config .ACL )
109109}
110110
111- func checkTextAccess (c context.Context , r * http.Request , tag string , id int64 ) (* Bug , * Crash , error ) {
111+ func checkTextAccess (ctx context.Context , r * http.Request , tag string , id int64 ) (* Bug , * Crash , error ) {
112112 switch tag {
113113 default :
114- return nil , nil , checkAccessLevel (c , r , AccessAdmin )
114+ return nil , nil , checkAccessLevel (ctx , r , AccessAdmin )
115115 case textPatch :
116- return nil , nil , checkJobTextAccess (c , r , "Patch" , id )
116+ return nil , nil , checkJobTextAccess (ctx , r , "Patch" , id )
117117 case textLog :
118- return nil , nil , checkJobTextAccess (c , r , "Log" , id )
118+ return nil , nil , checkJobTextAccess (ctx , r , "Log" , id )
119119 case textError :
120- return nil , nil , checkJobTextAccess (c , r , "Error" , id )
120+ return nil , nil , checkJobTextAccess (ctx , r , "Error" , id )
121121 case textKernelConfig :
122122 // This is checked based on text namespace.
123123 return nil , nil , nil
124124 case textCrashLog :
125125 // Log and Report can be attached to a Crash or Job.
126- bug , crash , err := checkCrashTextAccess (c , r , "Log" , id )
126+ bug , crash , err := checkCrashTextAccess (ctx , r , "Log" , id )
127127 if err == nil || err == ErrAccess {
128128 return bug , crash , err
129129 }
130- return nil , nil , checkJobTextAccess (c , r , "CrashLog" , id )
130+ return nil , nil , checkJobTextAccess (ctx , r , "CrashLog" , id )
131131 case textCrashReport :
132- bug , crash , err := checkCrashTextAccess (c , r , "Report" , id )
132+ bug , crash , err := checkCrashTextAccess (ctx , r , "Report" , id )
133133 if err == nil || err == ErrAccess {
134134 return bug , crash , err
135135 }
136- return nil , nil , checkJobTextAccess (c , r , "CrashReport" , id )
136+ return nil , nil , checkJobTextAccess (ctx , r , "CrashReport" , id )
137137 case textReproSyz :
138- return checkCrashTextAccess (c , r , "ReproSyz" , id )
138+ return checkCrashTextAccess (ctx , r , "ReproSyz" , id )
139139 case textReproC :
140- return checkCrashTextAccess (c , r , "ReproC" , id )
140+ return checkCrashTextAccess (ctx , r , "ReproC" , id )
141141 case textReproLog :
142- bug , crash , err := checkCrashTextAccess (c , r , "ReproLog" , id )
142+ bug , crash , err := checkCrashTextAccess (ctx , r , "ReproLog" , id )
143143 if err == nil || err == ErrAccess {
144144 return bug , crash , err
145145 }
146146 // ReproLog might also be referenced from Bug.ReproAttempts.Log
147147 // for failed repro attempts, but those are not exposed to non-admins
148148 // as of yet, so fallback to normal admin access check.
149- return nil , nil , checkAccessLevel (c , r , AccessAdmin )
149+ return nil , nil , checkAccessLevel (ctx , r , AccessAdmin )
150150 case textMachineInfo :
151151 // MachineInfo is deduplicated, so we can't find the exact crash/bug.
152152 // But since machine info is usually the same for all bugs and is not secret,
153153 // it's fine to check based on the namespace.
154154 return nil , nil , nil
155155 case textFsckLog :
156- return checkCrashTextAccess (c , r , "Assets.FsckLog" , id )
156+ return checkCrashTextAccess (ctx , r , "Assets.FsckLog" , id )
157157 }
158158}
159159
160- func checkCrashTextAccess (c context.Context , r * http.Request , field string , id int64 ) (* Bug , * Crash , error ) {
160+ func checkCrashTextAccess (ctx context.Context , r * http.Request , field string , id int64 ) (* Bug , * Crash , error ) {
161161 var crashes []* Crash
162162 keys , err := db .NewQuery ("Crash" ).
163163 Filter (field + "=" , id ).
164- GetAll (c , & crashes )
164+ GetAll (ctx , & crashes )
165165 if err != nil {
166166 return nil , nil , fmt .Errorf ("failed to query crashes: %w" , err )
167167 }
@@ -174,18 +174,18 @@ func checkCrashTextAccess(c context.Context, r *http.Request, field string, id i
174174 }
175175 crash := crashes [0 ]
176176 bug := new (Bug )
177- if err := db .Get (c , keys [0 ].Parent (), bug ); err != nil {
177+ if err := db .Get (ctx , keys [0 ].Parent (), bug ); err != nil {
178178 return nil , nil , fmt .Errorf ("failed to get bug: %w" , err )
179179 }
180- bugLevel := bug .sanitizeAccess (c , accessLevel (c , r ))
181- return bug , crash , checkAccessLevel (c , r , bugLevel )
180+ bugLevel := bug .sanitizeAccess (ctx , accessLevel (ctx , r ))
181+ return bug , crash , checkAccessLevel (ctx , r , bugLevel )
182182}
183183
184- func checkJobTextAccess (c context.Context , r * http.Request , field string , id int64 ) error {
184+ func checkJobTextAccess (ctx context.Context , r * http.Request , field string , id int64 ) error {
185185 keys , err := db .NewQuery ("Job" ).
186186 Filter (field + "=" , id ).
187187 KeysOnly ().
188- GetAll (c , nil )
188+ GetAll (ctx , nil )
189189 if err != nil {
190190 return fmt .Errorf ("failed to query jobs: %w" , err )
191191 }
@@ -198,15 +198,15 @@ func checkJobTextAccess(c context.Context, r *http.Request, field string, id int
198198 return err
199199 }
200200 bug := new (Bug )
201- if err := db .Get (c , keys [0 ].Parent (), bug ); err != nil {
201+ if err := db .Get (ctx , keys [0 ].Parent (), bug ); err != nil {
202202 return fmt .Errorf ("failed to get bug: %w" , err )
203203 }
204- bugLevel := bug .sanitizeAccess (c , accessLevel (c , r ))
205- return checkAccessLevel (c , r , bugLevel )
204+ bugLevel := bug .sanitizeAccess (ctx , accessLevel (ctx , r ))
205+ return checkAccessLevel (ctx , r , bugLevel )
206206}
207207
208- func (bug * Bug ) sanitizeAccess (c context.Context , currentLevel AccessLevel ) AccessLevel {
209- config := getConfig (c )
208+ func (bug * Bug ) sanitizeAccess (ctx context.Context , currentLevel AccessLevel ) AccessLevel {
209+ config := getConfig (ctx )
210210 for ri := len (bug .Reporting ) - 1 ; ri >= 0 ; ri -- {
211211 bugReporting := & bug .Reporting [ri ]
212212 if ri == 0 || ! bugReporting .Reported .IsZero () {
0 commit comments