X Tutup
The Wayback Machine - https://web.archive.org/web/20260304180133/https://github.com/github/codeql-go/pull/259
Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

CWE-352: Use of constant state in Oauth2 flow#259

Merged
owen-mc merged 8 commits intogithub:masterfrom
gagliardetto:oauth2-fixed-state
Jul 21, 2020
Merged

CWE-352: Use of constant state in Oauth2 flow#259
owen-mc merged 8 commits intogithub:masterfrom
gagliardetto:oauth2-fixed-state

Conversation

@gagliardetto
Copy link
Contributor

@gagliardetto gagliardetto commented Jul 16, 2020

CWE-352: Cross-Site Request Forgery (CSRF)

This query looks for cases where the oauth2 client uses a constant-value state string when creating the auth URL, which makes CSRF possible.

@gagliardetto gagliardetto changed the title Oauth2 fixed state CWE-352: Use of constant state in Oauth2 flow Jul 16, 2020
Copy link
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good. My only reservation is how this would treat a combination of a constant value and a non-constant value. I think that currently the query would report that, but it shouldn't. Luckily this is easy to change: just make ConstantStateFlowConf extend DataFlow::Configuration instead of TaintTracking::Configuration. Please also add a test case for this situation.

@gagliardetto
Copy link
Contributor Author

My only reservation is how this would treat a combination of a constant value and a non-constant value. I think that currently the query would report that, but it shouldn't. Luckily this is easy to change: just make ConstantStateFlowConf extend DataFlow::Configuration instead of TaintTracking::Configuration. Please also add a test case for this situation.

Yep, found that in a test run on lgtm.com

I think the best solution would be to keep the taint analysis, but only exclude cases where the constant joins a variable.

Now I just need to figure out how to write that into the query. Any suggestions? Maybe a similar situation in another query?

@sauyon
Copy link
Contributor

sauyon commented Jul 16, 2020

I think the best solution would be to keep the taint analysis, but only exclude cases where the constant joins a variable.

It seems to me like this isn't really necessary. What patterns are you hoping to catch by using taint flow? I think it might be better to include those specifically.

gagliardetto and others added 3 commits July 16, 2020 18:29
Co-authored-by: intrigus-lgtm <60750685+intrigus-lgtm@users.noreply.github.com>
@gagliardetto
Copy link
Contributor Author

It seems to me like this isn't really necessary. What patterns are you hoping to catch by using taint flow? I think it might be better to include those specifically.

I was thinking about cases where a call fmt.Sprintf only uses constants, and scenarios like that.

@gagliardetto
Copy link
Contributor Author

I was thinking about cases where a call fmt.Sprintf only uses constants, and scenarios like that.

You know what? I'll leave that out. So far haven't found a single example.

@gagliardetto
Copy link
Contributor Author

How do I fix the stubbed dependencies?

@smowton
Copy link
Contributor

smowton commented Jul 17, 2020

@gagliardetto could you elaborate what's wrong?

@gagliardetto
Copy link
Contributor Author

This query tests depend on golang.org/x/oauth2 package.

I need to somehow add this dependency without completely revolutionizing the go.mod file of codeql-go and without using the official vendoring mechanism of go mod (need to use depstubber instead).

I'm obviously doing something wrong with those two elements, but I'm not sure what.

@gagliardetto
Copy link
Contributor Author

gagliardetto commented Jul 17, 2020

That's the reason why the test fails, BTW.

@gagliardetto gagliardetto marked this pull request as ready for review July 17, 2020 10:05
@owen-mc
Copy link
Contributor

owen-mc commented Jul 20, 2020

@gagliardetto I believe it is failing because it doesn't have a go.mod file in the test folder. I made a file of that name with the following contents and then the tests passed.

module custom-queries-go-tests/constant-oauth2-state

go 1.14

require golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d

@gagliardetto
Copy link
Contributor Author

Thank you @owen-mc !

Copy link
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

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

Everything looks good. Thanks again for this contribution.

@owen-mc owen-mc merged commit 3018874 into github:master Jul 21, 2020
@gagliardetto
Copy link
Contributor Author

Thanks everyone!

@owen-mc owen-mc added the needs-polishing An external contribution that may need follow-up work. label Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-polishing An external contribution that may need follow-up work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup