ssh: use errors.As to detect PartialSuccessError wrapped in BannerError#353
Open
XananasX7 wants to merge 1 commit into
Open
ssh: use errors.As to detect PartialSuccessError wrapped in BannerError#353XananasX7 wants to merge 1 commit into
XananasX7 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The auth loop in newServerConn used a direct type assertion
(authErr.(*PartialSuccessError)) to detect partial-success authentication
results. This fails when a callback returns a *BannerError that wraps a
*PartialSuccessError, because the outer error is a *BannerError not a
*PartialSuccessError.
The banner-extraction code immediately above (lines 934-940) already
uses errors.As correctly for *BannerError. Apply the same treatment to
the *PartialSuccessError check: replace the direct type assertion with
errors.As so that wrapped PartialSuccessErrors are also handled.
The same fix is applied to the two candidate.result type assertions in
the PublicKeyCallback cache path, which can receive errors from the same
callbacks and is subject to the same wrapping pattern.
Without this fix, a callback returning &BannerError{Err: &PartialSuccessError{...}}
would cause the partial-success response to be silently treated as an
authentication failure, incrementing authFailures and sending the client
a failure message instead of a partial-success message.
Fixes golang/go#79809
42022f0 to
33e1572
Compare
Author
|
Fixes golang/go#79809 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The authentication loop in
newServerConnused a direct type assertionauthErr.(*PartialSuccessError)to detect partial-success responses fromauthentication callbacks. This silently fails when a callback returns a
*BannerErrorthat wraps a*PartialSuccessError.Background
BannerErrorhas anErrfield and implementsUnwrap(), making it astandard Go error-wrapping type. The
PartialSuccessErrordoc says it "canbe returned by any of the ServerConfig authentication callbacks" — the
same callbacks that may also return
BannerError. It is therefore valid andexpected for a callback to return:
This allows a callback to simultaneously send a banner message to the client
and signal partial success requiring a further authentication step.
Bug
With the old direct type assertion:
When
authErris a*BannerError(wrapping a*PartialSuccessError),okis
false. The partial-success state is lost:authFailuresis incremented,the
authConfigis not updated topartialSuccess.Next, and the clientreceives
SSH_MSG_USERAUTH_FAILUREinstead ofSSH_MSG_USERAUTH_PARTIAL_SUCCESS.The banner-extraction code on the lines immediately above (lines 934-940)
already handles exactly this pattern correctly using
errors.As:Fix
Replace the three direct
*PartialSuccessErrortype assertions witherrors.As, matching the pattern already used for*BannerError:Main auth loop (
authErrpath, line ~949): the primary fix — ensurespartialSuccess.Nextis used to updateauthConfigeven when wrapped.PublicKeyCallback cache, first check (line ~782): ensures the
"invalid library usage" detection works when wrapped.
PublicKeyCallback cache, isQuery check (line ~807): ensures the
public-key query response (
SSH_MSG_USERAUTH_PK_OK) is sent correctlywhen the callback result wraps a
PartialSuccessError.Test
A new test
TestPartialSuccessErrorWrappedInBannerErroris added toserver_multi_auth_test.gothat:PasswordCallbackreturning&BannerError{Err: &PartialSuccessError{...}}methods remain" because the partial-success state is discarded)
Relation to Previous Fix
This is the symmetric counterpart to the
*BannerErrorerrors.Asfixalready applied in the codebase: that fix ensures a
BannerErrorwrappedin another error is detected; this fix ensures a
PartialSuccessErrorwrapped in a
BannerErroris detected.