@@ -22,7 +22,7 @@ func testDbMethods(bdb *orm.DB, untrustedSource *http.Request) {
2222
2323// BAD: using untrusted data to build SQL queries (QueryBuilder does not sanitize its arguments)
2424func testQueryBuilderMethods (qb orm.QueryBuilder , untrustedSource * http.Request ) {
25- untrusted := untrustedSource .UserAgent () // $ Source[go/sql-injection]
25+ untrusted := untrustedSource .UserAgent () // $ Source[go/sql-injection]
2626 untrusted2 := untrustedSource .UserAgent () // $ Source[go/sql-injection]
2727
2828 qb .Select (untrusted ) // $ querystring=untrusted Alert[go/sql-injection]
@@ -55,14 +55,14 @@ func testOrmerRaw(ormer orm.Ormer, untrustedSource *http.Request) {
5555
5656func testFilterRaw (querySeter orm.QuerySeter , untrustedSource * http.Request ) {
5757 untrusted := untrustedSource .UserAgent () // $ Source[go/sql-injection]
58- querySeter .FilterRaw (untrusted , "safe" ) // $ querystring="safe" // GOOD: untrusted used as a column name
59- querySeter .FilterRaw ("safe" , untrusted ) // $ querystring=untrusted Alert[go/sql-injection] // BAD: untrusted used as a SQL fragment
58+ querySeter .FilterRaw (untrusted , "safe" ) // $ querystring="safe" // GOOD: untrusted used as a column name
59+ querySeter .FilterRaw ("safe" , untrusted ) // $ querystring=untrusted Alert[go/sql-injection] // BAD: untrusted used as a SQL fragment
6060}
6161
6262func testConditionRaw (cond orm.Condition , untrustedSource * http.Request ) {
6363 untrusted := untrustedSource .UserAgent () // $ Source[go/sql-injection]
64- cond .Raw (untrusted , "safe" ) // $ querystring="safe" // GOOD: untrusted used as a column name
65- cond .Raw ("safe" , untrusted ) // $ querystring=untrusted Alert[go/sql-injection] // BAD: untrusted used as a SQL fragment
64+ cond .Raw (untrusted , "safe" ) // $ querystring="safe" // GOOD: untrusted used as a column name
65+ cond .Raw ("safe" , untrusted ) // $ querystring=untrusted Alert[go/sql-injection] // BAD: untrusted used as a SQL fragment
6666}
6767
6868type SubStruct struct {
@@ -77,90 +77,90 @@ type MyStruct struct {
7777// BAD: (possible stored XSS) retrieving data from a database then writing to an HTTP response
7878func testOrmerReads (ormer orm.Ormer , sink http.ResponseWriter ) {
7979 obj := MyStruct {}
80- ormer .Read (& obj ) // $ Source[go/stored-xss]
81- sink .Write ([]byte (obj .field )) // $ Alert[go/stored-xss]
80+ ormer .Read (& obj ) // $ Source[go/stored-xss]
81+ sink .Write ([]byte (obj .field )) // $ Alert[go/stored-xss]
8282 sink .Write ([]byte (obj .substructs [0 ].field )) // $ Alert[go/stored-xss]
8383
8484 obj2 := MyStruct {}
85- ormer .ReadForUpdate (& obj2 ) // $ Source[go/stored-xss]
85+ ormer .ReadForUpdate (& obj2 ) // $ Source[go/stored-xss]
8686 sink .Write ([]byte (obj2 .field )) // $ Alert[go/stored-xss]
8787
8888 obj3 := MyStruct {}
8989 ormer .ReadOrCreate (& obj3 , "arg" ) // $ Source[go/stored-xss]
90- sink .Write ([]byte (obj3 .field )) // $ Alert[go/stored-xss]
90+ sink .Write ([]byte (obj3 .field )) // $ Alert[go/stored-xss]
9191}
9292
9393// BAD: (possible stored XSS) retrieving data from a database then writing to an HTTP response
9494func testFieldReads (textField * orm.TextField , jsonField * orm.JSONField , jsonbField * orm.JsonbField , sink http.ResponseWriter ) {
95- sink .Write ([]byte (textField .Value ())) // $ Alert[go/stored-xss]
96- sink .Write ([]byte (textField .RawValue ().(string ))) // $ Alert[go/stored-xss]
97- sink .Write ([]byte (textField .String ())) // $ Alert[go/stored-xss]
98- sink .Write ([]byte (jsonField .Value ())) // $ Alert[go/stored-xss]
99- sink .Write ([]byte (jsonField .RawValue ().(string ))) // $ Alert[go/stored-xss]
100- sink .Write ([]byte (jsonField .String ())) // $ Alert[go/stored-xss]
101- sink .Write ([]byte (jsonbField .Value ())) // $ Alert[go/stored-xss]
95+ sink .Write ([]byte (textField .Value ())) // $ Alert[go/stored-xss]
96+ sink .Write ([]byte (textField .RawValue ().(string ))) // $ Alert[go/stored-xss]
97+ sink .Write ([]byte (textField .String ())) // $ Alert[go/stored-xss]
98+ sink .Write ([]byte (jsonField .Value ())) // $ Alert[go/stored-xss]
99+ sink .Write ([]byte (jsonField .RawValue ().(string ))) // $ Alert[go/stored-xss]
100+ sink .Write ([]byte (jsonField .String ())) // $ Alert[go/stored-xss]
101+ sink .Write ([]byte (jsonbField .Value ())) // $ Alert[go/stored-xss]
102102 sink .Write ([]byte (jsonbField .RawValue ().(string ))) // $ Alert[go/stored-xss]
103- sink .Write ([]byte (jsonbField .String ())) // $ Alert[go/stored-xss]
103+ sink .Write ([]byte (jsonbField .String ())) // $ Alert[go/stored-xss]
104104}
105105
106106// BAD: (possible stored XSS) retrieving data from a database then writing to an HTTP response
107107func testQuerySeterReads (qs orm.QuerySeter , sink http.ResponseWriter ) {
108108 var objs []* MyStruct
109- qs .All (& objs ) // $ Source[go/stored-xss]
109+ qs .All (& objs ) // $ Source[go/stored-xss]
110110 sink .Write ([]byte (objs [0 ].field )) // $ Alert[go/stored-xss]
111111
112112 var obj MyStruct
113- qs .One (& obj ) // $ Source[go/stored-xss]
113+ qs .One (& obj ) // $ Source[go/stored-xss]
114114 sink .Write ([]byte (obj .field )) // $ Alert[go/stored-xss]
115115
116116 var allMaps []orm.Params
117- qs .Values (& allMaps ) // $ Source[go/stored-xss]
117+ qs .Values (& allMaps ) // $ Source[go/stored-xss]
118118 sink .Write ([]byte (allMaps [0 ]["field" ].(string ))) // $ Alert[go/stored-xss]
119119
120120 var allLists []orm.ParamsList
121- qs .ValuesList (& allLists ) // $ Source[go/stored-xss]
121+ qs .ValuesList (& allLists ) // $ Source[go/stored-xss]
122122 sink .Write ([]byte (allLists [0 ][0 ].(string ))) // $ Alert[go/stored-xss]
123123
124124 var oneList orm.ParamsList
125- qs .ValuesFlat (& oneList , "colname" ) // $ Source[go/stored-xss]
125+ qs .ValuesFlat (& oneList , "colname" ) // $ Source[go/stored-xss]
126126 sink .Write ([]byte (oneList [0 ].(string ))) // $ Alert[go/stored-xss]
127127
128128 var oneRowMap orm.Params
129- qs .RowsToMap (& oneRowMap , "key" , "value" ) // $ Source[go/stored-xss]
129+ qs .RowsToMap (& oneRowMap , "key" , "value" ) // $ Source[go/stored-xss]
130130 sink .Write ([]byte (oneRowMap ["field" ].(string ))) // $ Alert[go/stored-xss]
131131
132132 var oneRowStruct MyStruct
133133 qs .RowsToStruct (& oneRowStruct , "key" , "value" ) // $ Source[go/stored-xss]
134- sink .Write ([]byte (oneRowStruct .field )) // $ Alert[go/stored-xss]
134+ sink .Write ([]byte (oneRowStruct .field )) // $ Alert[go/stored-xss]
135135}
136136
137137// BAD: (possible stored XSS) retrieving data from a database then writing to an HTTP response
138138func testRawSeterReads (rs orm.RawSeter , sink http.ResponseWriter ) {
139139 var allMaps []orm.Params
140- rs .Values (& allMaps ) // $ Source[go/stored-xss]
140+ rs .Values (& allMaps ) // $ Source[go/stored-xss]
141141 sink .Write ([]byte (allMaps [0 ]["field" ].(string ))) // $ Alert[go/stored-xss]
142142
143143 var allLists []orm.ParamsList
144- rs .ValuesList (& allLists ) // $ Source[go/stored-xss]
144+ rs .ValuesList (& allLists ) // $ Source[go/stored-xss]
145145 sink .Write ([]byte (allLists [0 ][0 ].(string ))) // $ Alert[go/stored-xss]
146146
147147 var oneList orm.ParamsList
148- rs .ValuesFlat (& oneList , "colname" ) // $ Source[go/stored-xss]
148+ rs .ValuesFlat (& oneList , "colname" ) // $ Source[go/stored-xss]
149149 sink .Write ([]byte (oneList [0 ].(string ))) // $ Alert[go/stored-xss]
150150
151151 var oneRowMap orm.Params
152- rs .RowsToMap (& oneRowMap , "key" , "value" ) // $ Source[go/stored-xss]
152+ rs .RowsToMap (& oneRowMap , "key" , "value" ) // $ Source[go/stored-xss]
153153 sink .Write ([]byte (oneRowMap ["field" ].(string ))) // $ Alert[go/stored-xss]
154154
155155 var oneRowStruct MyStruct
156156 rs .RowsToStruct (& oneRowStruct , "key" , "value" ) // $ Source[go/stored-xss]
157- sink .Write ([]byte (oneRowStruct .field )) // $ Alert[go/stored-xss]
157+ sink .Write ([]byte (oneRowStruct .field )) // $ Alert[go/stored-xss]
158158
159159 var strField string
160- rs .QueryRow (& strField ) // $ Source[go/stored-xss]
160+ rs .QueryRow (& strField ) // $ Source[go/stored-xss]
161161 sink .Write ([]byte (strField )) // $ Alert[go/stored-xss]
162162
163163 var strFields []string
164- rs .QueryRows (& strFields ) // $ Source[go/stored-xss]
164+ rs .QueryRows (& strFields ) // $ Source[go/stored-xss]
165165 sink .Write ([]byte (strFields [0 ])) // $ Alert[go/stored-xss]
166166}
0 commit comments