Skip to content

Commit ed27142

Browse files
authored
source config size validation (#7)
* source config file size check added
1 parent 0e2e39b commit ed27142

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

internal/config_reader_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/source_config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package internal
22

33
import (
44
"encoding/json"
5+
"errors"
56
"io"
67
"net/url"
78
"os"
89
"strconv"
910
)
1011

12+
const MAX_CONFIG_FILE_SIZE = 3 * 1024 // 3kB max for config file
13+
1114
type SourceConfig struct {
1215
InboundsSettings []InboundEntity `json:"inbounds"`
1316
LogSettings `json:"log"`
@@ -119,6 +122,17 @@ func NewSourceConfig(fileName string) (SourceConfig, error) {
119122
}
120123
defer file.Close()
121124

125+
// getting file stats to check the size
126+
fileStat, err := file.Stat()
127+
if err != nil {
128+
return cfg, err
129+
}
130+
131+
// checking if the size exceeds max value
132+
if fileStat.Size() > MAX_CONFIG_FILE_SIZE {
133+
return cfg, errors.New("config file too large")
134+
}
135+
122136
// reading the file contents
123137
fileContent, err := io.ReadAll(file)
124138
if err != nil {

0 commit comments

Comments
 (0)