|
| 1 | +/** |
| 2 | + * Provides classes for modeling the `github.com/gin-contrib/cors` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** |
| 8 | + * Provides classes for modeling the `github.com/gin-contrib/cors` package. |
| 9 | + */ |
| 10 | +module GinCors { |
| 11 | + /** Gets the package name `github.com/gin-gonic/gin`. */ |
| 12 | + string packagePath() { result = package("github.com/gin-contrib/cors", "") } |
| 13 | + |
| 14 | + /** |
| 15 | + * A new function create a new gin Handler that passed to gin as middleware |
| 16 | + */ |
| 17 | + class New extends Function { |
| 18 | + New() { exists(Function f | f.hasQualifiedName(packagePath(), "New") | this = f) } |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * A write to the value of Access-Control-Allow-Credentials header |
| 23 | + */ |
| 24 | + class AllowCredentialsWrite extends DataFlow::ExprNode { |
| 25 | + DataFlow::Node base; |
| 26 | + |
| 27 | + AllowCredentialsWrite() { |
| 28 | + exists(Field f, Write w | |
| 29 | + f.hasQualifiedName(packagePath(), "Config", "AllowCredentials") and |
| 30 | + w.writesField(base, f, this) and |
| 31 | + this.getType() instanceof BoolType |
| 32 | + ) |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Get config struct holding header values |
| 37 | + */ |
| 38 | + DataFlow::Node getBase() { result = base } |
| 39 | + |
| 40 | + /** |
| 41 | + * Get config variable holding header values |
| 42 | + */ |
| 43 | + GinConfig getConfig() { |
| 44 | + exists(GinConfig gc | |
| 45 | + ( |
| 46 | + gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() = |
| 47 | + base.asInstruction() or |
| 48 | + gc.getV().getAUse() = base |
| 49 | + ) and |
| 50 | + result = gc |
| 51 | + ) |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * A write to the value of Access-Control-Allow-Origins header |
| 57 | + */ |
| 58 | + class AllowOriginsWrite extends DataFlow::ExprNode { |
| 59 | + DataFlow::Node base; |
| 60 | + |
| 61 | + AllowOriginsWrite() { |
| 62 | + exists(Field f, Write w | |
| 63 | + f.hasQualifiedName(packagePath(), "Config", "AllowOrigins") and |
| 64 | + w.writesField(base, f, this) and |
| 65 | + this.asExpr() instanceof SliceLit |
| 66 | + ) |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Get config struct holding header values |
| 71 | + */ |
| 72 | + DataFlow::Node getBase() { result = base } |
| 73 | + |
| 74 | + /** |
| 75 | + * Get config variable holding header values |
| 76 | + */ |
| 77 | + GinConfig getConfig() { |
| 78 | + exists(GinConfig gc | |
| 79 | + ( |
| 80 | + gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() = |
| 81 | + base.asInstruction() or |
| 82 | + gc.getV().getAUse() = base |
| 83 | + ) and |
| 84 | + result = gc |
| 85 | + ) |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * A write to the value of Access-Control-Allow-Origins of value "*", overriding AllowOrigins |
| 91 | + */ |
| 92 | + class AllowAllOriginsWrite extends DataFlow::ExprNode { |
| 93 | + DataFlow::Node base; |
| 94 | + |
| 95 | + AllowAllOriginsWrite() { |
| 96 | + exists(Field f, Write w | |
| 97 | + f.hasQualifiedName(packagePath(), "Config", "AllowAllOrigins") and |
| 98 | + w.writesField(base, f, this) and |
| 99 | + this.getType() instanceof BoolType |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Get config struct holding header values |
| 105 | + */ |
| 106 | + DataFlow::Node getBase() { result = base } |
| 107 | + |
| 108 | + /** |
| 109 | + * Get config variable holding header values |
| 110 | + */ |
| 111 | + GinConfig getConfig() { |
| 112 | + exists(GinConfig gc | |
| 113 | + ( |
| 114 | + gc.getV().getBaseVariable().getDefinition().(SsaExplicitDefinition).getRhs() = |
| 115 | + base.asInstruction() or |
| 116 | + gc.getV().getAUse() = base |
| 117 | + ) and |
| 118 | + result = gc |
| 119 | + ) |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * A variable of type Config that holds the headers to be set. |
| 125 | + */ |
| 126 | + class GinConfig extends Variable { |
| 127 | + SsaWithFields v; |
| 128 | + |
| 129 | + GinConfig() { |
| 130 | + this = v.getBaseVariable().getSourceVariable() and |
| 131 | + exists(Type t | t.hasQualifiedName(packagePath(), "Config") | v.getType() = t) |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Get variable declaration of GinConfig |
| 136 | + */ |
| 137 | + SsaWithFields getV() { result = v } |
| 138 | + } |
| 139 | +} |
0 commit comments