Skip to content

Feat: Add input validation for KeyID and TeamID #14

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.23' ]
go: [ '1.24.2' ]
steps:
- name: Set up Go v${{ matrix.go }}
uses: actions/setup-go@v4
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Install deps
run: |
go version
go get -v -d ./...
go mod download && go mod verify

- name: Cache modules
uses: actions/cache@v3
Expand All @@ -47,7 +47,7 @@ jobs:
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o apnscmd_darwin_amd64
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o apnscmd_darwin_arm64

- uses: "marvinpinto/action-automatic-releases@latest"
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: CI Check PR

on: [ pull_request_target ]
on: [ pull_request ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.23' ]
go: [ '1.24.2' ]
steps:
- name: Set up Go v${{ matrix.go }}
uses: actions/setup-go@v4
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Install deps
run: |
go version
go get -v -d ./...
go mod download && go mod verify

- name: Cache modules
uses: actions/cache@v3
Expand Down
33 changes: 31 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,24 @@ func getClient(cert *tls.Certificate) (client *http.Client, err error) {
Certificates: []tls.Certificate{*cert},
RootCAs: caCertPool,
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS12,
}
} else {
tlsConfig = &tls.Config{
RootCAs: caCertPool,
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS12,
}
}
} else if cert != nil {
tlsConfig = &tls.Config{Certificates: []tls.Certificate{*cert}}
tlsConfig = &tls.Config{
Certificates: []tls.Certificate{*cert},
MinVersion: tls.VersionTLS12,
}
} else {
tlsConfig = &tls.Config{}
tlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}

client = &http.Client{Timeout: 20 * time.Second}
Expand Down Expand Up @@ -279,6 +286,28 @@ func main() {
}
}

// Validate KeyID
if KeyID != "" {
if len(KeyID) != 10 {
log.Fatalf("Error: -key-id must be 10 characters long.")
}
matched, _ := regexp.MatchString("^[a-zA-Z0-9]+$", KeyID)
if !matched {
log.Fatalf("Error: -key-id must be alphanumeric.")
}
}

// Validate TeamID
if TeamID != "" {
if len(TeamID) != 10 {
log.Fatalf("Error: -team-id must be 10 characters long.")
}
matched, _ := regexp.MatchString("^[a-zA-Z0-9]+$", TeamID)
if !matched {
log.Fatalf("Error: -team-id must be alphanumeric.")
}
}

bearerToken := func() string {
if len(AuthTokenPath) > 0 {
bt, err := getClientBearerToken()
Expand Down