File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -18,12 +18,32 @@ limitations under the License.
1818package services
1919
2020import (
21+ "regexp"
22+ "strings"
23+
2124 "github.com/apache/incubator-devlake/core/dal"
2225 "github.com/apache/incubator-devlake/core/errors"
2326)
2427
2528// InsertRow FIXME ...
2629func InsertRow (table string , rows []map [string ]interface {}) (int64 , errors.Error ) {
30+ if ! regexp .MustCompile (`^[a-zA-Z0-9_]+$` ).MatchString (table ) {
31+ return 0 , errors .BadInput .New ("table name invalid" )
32+ }
33+
34+ if allowedTables := cfg .GetString ("PUSH_API_ALLOWED_TABLES" ); allowedTables != "" {
35+ allow := false
36+ for _ , t := range strings .Split (allowedTables , "," ) {
37+ if strings .TrimSpace (t ) == table {
38+ allow = true
39+ break
40+ }
41+ }
42+ if ! allow {
43+ return 0 , errors .Forbidden .New ("table name is not in the allowed list" )
44+ }
45+ }
46+
2747 err := db .Create (rows , dal .From (table ))
2848 if err != nil {
2949 return 0 , err
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ SKIP_SUBTASK_PROGRESS=false
3434PORT=8080
3535MODE=release
3636
37+ # PUSH_API_ALLOWED_TABLES=table1,table2
3738NOTIFICATION_ENDPOINT=
3839NOTIFICATION_SECRET=
3940
You can’t perform that action at this time.
0 commit comments