Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail Credentials validation if it contains extra data #276

Merged
merged 3 commits into from
Mar 11, 2024

Conversation

dblanchette
Copy link
Contributor

This is especially useful for "target_tags" for which a malformed value could lead to a credentials leak

@dblanchette dblanchette requested a review from a team as a code owner March 7, 2024 22:12
return nil, fmt.Errorf("entry %s: invalid credentials data: %v", id, err)
}
var validationErrors error
credentialsMap["type"] = credentialsType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça c'est vraiment l'incarnation golang de :sifflercommeunépais: et :ctutoéquipisse-ouainmaisçaapasderapport:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouais je n'avais pas trop le choix de faire une passe de même ou de réécrire une grosse partie du code ou de faire un genre de deepcopy maison 🤷🏻

Copy link

@mikebaum mikebaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved, because technically there's nothing wrong with the code. Just made a couple of minor suggestions.

if err != nil {
validationErrors = multierror.Append(validationErrors, fmt.Errorf("entry %s: unable to create a decoder: %v", id, err))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of go 1.20, they added this to the std lib. You can simply use this. If this project is not at version 1.20, then this is fine unless you want to update the version of go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project is using Go 1.21, so that should be ok.

But, I tried using the package and I don't like the interface, so I don't think it's worth it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thought the interface was kinda the same. In any case multierror is fine.

if err != nil {
validationErrors = multierror.Append(validationErrors, fmt.Errorf("entry %s: unable to create a decoder: %v", id, err))
}
if err := decoder.Decode(credentialsMap); err != nil {
return nil, fmt.Errorf("entry %s: invalid credentials data: %v", id, err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No part of the code you changed, but the error created here should be rather:

fmt.Errorf("entry %s: invalid credentials data: %w", id, err)

%w is used for wrapping an error and should be used instead of %v when the value is an error.

}

cred, err := ParseSingleCredentials(credMap)
assert.Nil(t, err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:
assert.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that explains it! assert.Nil(t, err) is used elsewhere in the code and it did not fail when it should have

@dblanchette dblanchette merged commit f1bb1ee into main Mar 11, 2024
3 checks passed
@dblanchette dblanchette deleted the fix/DT-6821-extra-data-crash branch March 11, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants