|
| 1 | +/** |
| 2 | + * @name PAM authorization bypass due to incorrect usage |
| 3 | + * @description Not using `pam.AcctMgmt` after `pam.Authenticate` to check the validity of a login can lead to authorization bypass. |
| 4 | + * @kind problem |
| 5 | + * @problem.severity warning |
| 6 | + * @id go/unreachable-statement |
| 7 | + * @tags maintainability |
| 8 | + * correctness |
| 9 | + * external/cwe/cwe-561 |
| 10 | + * external/cwe/cwe-285 |
| 11 | + * @precision very-high |
| 12 | + */ |
| 13 | + |
| 14 | +import go |
| 15 | + |
| 16 | +predicate isInTestFile(Expr r) { |
| 17 | + r.getFile().getAbsolutePath().matches("%test%") and |
| 18 | + not r.getFile().getAbsolutePath().matches("%/ql/test/%") |
| 19 | +} |
| 20 | + |
| 21 | +class PamAuthenticate extends Method { |
| 22 | + PamAuthenticate() { |
| 23 | + this.hasQualifiedName("github.com/msteinert/pam", "Transaction", "Authenticate") |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +class PamAcctMgmt extends Method { |
| 28 | + PamAcctMgmt() { this.hasQualifiedName("github.com/msteinert/pam", "Transaction", "AcctMgmt") } |
| 29 | +} |
| 30 | + |
| 31 | +class PamStartFunc extends Function { |
| 32 | + PamStartFunc() { this.hasQualifiedName("github.com/msteinert/pam", ["StartFunc", "Start"]) } |
| 33 | +} |
| 34 | + |
| 35 | +class PamStartToAcctMgmtConfig extends TaintTracking::Configuration { |
| 36 | + PamStartToAcctMgmtConfig() { this = "PAM auth bypass (Start to AcctMgmt)" } |
| 37 | + |
| 38 | + override predicate isSource(DataFlow::Node source) { |
| 39 | + exists(PamStartFunc p | p.getACall().getResult(0) = source) |
| 40 | + } |
| 41 | + |
| 42 | + override predicate isSink(DataFlow::Node sink) { |
| 43 | + exists(PamAcctMgmt p | p.getACall().getReceiver() = sink) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +class PamStartToAuthenticateConfig extends TaintTracking::Configuration { |
| 48 | + PamStartToAuthenticateConfig() { this = "PAM auth bypass (Start to Authenticate)" } |
| 49 | + |
| 50 | + override predicate isSource(DataFlow::Node source) { |
| 51 | + exists(PamStartFunc p | p.getACall().getResult(0) = source) |
| 52 | + } |
| 53 | + |
| 54 | + override predicate isSink(DataFlow::Node sink) { |
| 55 | + exists(PamAuthenticate p | p.getACall().getReceiver() = sink) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +from |
| 60 | + PamStartToAcctMgmtConfig acctMgmtConfig, PamStartToAuthenticateConfig authConfig, |
| 61 | + DataFlow::Node source, DataFlow::Node sink |
| 62 | +where |
| 63 | + not isInTestFile(source.asExpr()) and |
| 64 | + (authConfig.hasFlow(source, sink) and not acctMgmtConfig.hasFlow(source, _)) |
| 65 | +select source, "This Pam transaction may not be secure." |
0 commit comments