Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix all gosec Security Issues #43

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions .github/workflows/gosec-scan.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,63 @@
name: Run Gosec in CODESOURCERER

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
tests:
security-scan:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v3
- name: Run Gosec Security Scanner

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Cache Go Modules for Github Service
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
src/github/go.sum
key: ${{ runner.os }}-go-${{ hashFiles('src/github/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Cache Go Modules for GenAI Service
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
src/genAi/go.sum
key: ${{ runner.os }}-go-${{ hashFiles('src/genAi/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install Dependencies for Github Service
run: |
cd src/github
go mod tidy

- name: Install Dependencies for GenAI Service
run: |
cd src/genAi
go mod tidy

- name: Run Gosec for Github Service
uses: securego/gosec@master
with:
args: ./src/github/...

- name: Run Gosec for GenAI Service
uses: securego/gosec@master
with:
args: ./...
args: ./src/genAi/...
3 changes: 2 additions & 1 deletion src/genAi/utils/loadenvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package utils
import (
"bufio"
"os"
"path/filepath"
"strings"
)

func Loadenv(filePath string) (map[string]string, error) {
envs := make(map[string]string)

file, err := os.Open(filePath)
file, err := os.Open(filepath.Clean(filePath))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion src/github/controllers/generators/genTestfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GenerateTestFiles(tests []struct {
}) error {
for _, test := range tests {
dir := filepath.Dir(test.TestPath)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
if err := os.MkdirAll(dir, 0750); err != nil {
return fmt.Errorf("unable to create directory %s: %w", dir, err)
}
file, err := os.Create(test.TestPath)
Expand Down
3 changes: 2 additions & 1 deletion src/github/controllers/tokenhandlers/JWThandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github/utils"
"log"
"os"
"path/filepath"
"time"

"github.com/golang-jwt/jwt/v4"
Expand Down Expand Up @@ -33,7 +34,7 @@ func GetJWT() string {
}

func GenerateJWT(appID string, privkeyPath string) (string, error) {
privkeyBytes, err := os.ReadFile(privkeyPath)
privkeyBytes, err := os.ReadFile(filepath.Clean(privkeyPath))
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion src/github/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/google/go-github/v52 v52.0.0
golang.org/x/oauth2 v0.24.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down Expand Up @@ -38,5 +39,4 @@ require (
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 2 additions & 1 deletion src/github/utils/loadenvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package utils
import (
"bufio"
"os"
"path/filepath"
"strings"
)

func Loadenv(filePath string) (map[string]string, error) {
envs := make(map[string]string)

file, err := os.Open(filePath)
file, err := os.Open(filepath.Clean(filePath))
if err != nil {
return nil, err
}
Expand Down
Loading