-
Notifications
You must be signed in to change notification settings - Fork 29
Use whitelist to restrict permission to user profile override #495
Changes from 1 commit
1c93e3a
ede7e01
40e4623
06ade20
34a4fed
85ac0b5
2f01262
1abdb8a
102434d
bd8bbda
e0bd158
90c76db
488b055
f9f7835
708fc53
e6ae19b
47bc755
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,13 +198,16 @@ func (c *TenantController) loadUserTenantConfiguration(ctx context.Context, conf | |
return config, err | ||
} | ||
resp, err := authClient.ShowUser(ctx, auth.ShowUserPath(), nil, nil) | ||
defer resp.Body.Close() | ||
|
||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot to remove lines 202-205 I guess (duplicates 208-211) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, these 2 errors are different: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you are right! Looks good to me now. |
||
log.Error(ctx, map[string]interface{}{"auth_url": auth.ShowUserPath()}, "unable to get user info") | ||
return config, errs.Wrapf(err, "failed to GET url %s due to error", auth.ShowUserPath()) | ||
} | ||
if resp.StatusCode < 200 || resp.StatusCode > 300 { | ||
return config, fmt.Errorf("failed to GET url %s due to status code %d", resp.Request.URL, resp.StatusCode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to read the body here too because otherwise it may leak FD even if you close the body :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, let me move this line just after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If response is not a JSON (if it's not 200) then simplejson.NewFromReader(resp.Body) will fail I guess. So, instead do the following:
Or
Or simply use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, thanks for the explanations, @alexeykazakov. Am I wrong or does
reads the body but does not return it ? I thought we should read it once only ? Or at least once ? (In Java you cannot read the streams multiple times) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 06ade20 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hopefully ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. It reads the stream to make sure it's empty and then closes the body. If stream is already empty (body has been read) that's OK. It doesn't do any harm. |
||
} | ||
|
||
js, err := simplejson.NewFromReader(resp.Body) | ||
if err != nil { | ||
return config, err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close response body in defer and make sure the body has been read. Otherwise you will leak FDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, indeed! thanks, @alexeykazakov!