Skip to content

Commit 6583bf2

Browse files
author
Kenneth Rosario
authored
chore: configure codeql vulnerability scanning (#170)
1 parent 06264b6 commit 6583bf2

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.github/workflows/codeql.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "master" ]
9+
10+
jobs:
11+
analyze:
12+
name: Analyze
13+
runs-on: ubuntu-latest
14+
permissions:
15+
actions: read
16+
contents: read
17+
security-events: write
18+
19+
strategy:
20+
fail-fast: false
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
# Initializes the CodeQL tools for scanning.
27+
- name: Initialize CodeQL
28+
uses: github/codeql-action/init@v2
29+
with:
30+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
31+
languages: go
32+
# If you wish to specify custom queries, you can do so here or in a config file.
33+
# By default, queries listed here will override any specified in a config file.
34+
# Prefix the list here with "+" to use these queries and those in the config file.
35+
36+
# Details on CodeQL's query packs refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
37+
# queries: security-extended,security-and-quality
38+
39+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
40+
- name: Autobuild
41+
uses: github/codeql-action/autobuild@v2
42+
43+
- name: Perform CodeQL Analysis
44+
uses: github/codeql-action/analyze@v2
45+
with:
46+
category: "/language:go"

funcframework/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func encodeData(d interface{}) ([]byte, error) {
217217
// associated with the given CloudEvent service. See ceServiceToResourceRe for the regexp
218218
// mapping. For example,
219219
//
220-
// "projects/_/buckets/some-bucket/objects/folder/test.txt"
220+
// "projects/_/buckets/some-bucket/objects/folder/test.txt"
221221
//
222222
// would be split to create the strings "projects/_/buckets/some-bucket"
223223
// and "objects/folder/test.txt". This function returns the resource string, the

internal/events/pubsub/pubsub.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package pubsub
44
import (
55
"fmt"
66
"regexp"
7+
"strings"
78
"time"
89

910
"cloud.google.com/go/functions/metadata"
@@ -50,8 +51,11 @@ func ExtractTopicFromRequestPath(path string) (string, error) {
5051
re := regexp.MustCompile(`(projects\/[^/?]+\/topics\/[^/?]+)/*`)
5152
matches := re.FindStringSubmatch(path)
5253
if matches == nil {
54+
// Prevent log injection by removing newline characters in path
55+
replacer := strings.NewReplacer("\n", "", "\r", "")
56+
escapedPath := replacer.Replace(path)
5357
return "", fmt.Errorf("failed to extract Pub/Sub topic name from the URL request path: %q, configure your subscription's push endpoint to use the following path pattern: 'projects/PROJECT_NAME/topics/TOPIC_NAME'",
54-
path)
58+
escapedPath)
5559
}
5660

5761
// Index 0 is the entire input string matched, index 1 is the first submatch

0 commit comments

Comments
 (0)