Skip to content

Commit

Permalink
Merge pull request #11 from veqryn/use-upstream-sanitization
Browse files Browse the repository at this point in the history
Use upstream sanitization
  • Loading branch information
veqryn authored Mar 26, 2024
2 parents cc53efc + 88de946 commit 6a3365e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 394 deletions.
26 changes: 9 additions & 17 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
#schedule:
#- cron: '38 15 * * 5'
#- cron: '28 21 * * 1'
push:
branches: [ "main" ]

Expand All @@ -26,47 +26,39 @@ jobs:
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
# Uncomment the permissions below if installing in a private repository.
# contents: read
# actions: read

steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
with:
results_file: results.sarif
results_format: sarif
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
# - you want to enable the Branch-Protection check on a *public* repository, or
# - you are installing Scorecard on a *private* repository
# you want to enable the Branch-Protection check on a *public* repository, or
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
# repo_token: ${{ secrets.SCORECARD_TOKEN }}

# Public repositories:
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories:
# - `publish_results` will always be set to `false`, regardless
# of the value entered here.
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4
uses: github/codeql-action/upload-sarif@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
with:
sarif_file: results.sarif
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Never forget to snag another bug again.
### Other Great SLOG Utilities
- [slogctx](https://github.com/veqryn/slog-context): Add attributes to context and have them automatically added to all log lines. Work with a logger stored in context.
- [slogotel](https://github.com/veqryn/slog-context/tree/main/otel): Automatically extract and add [OpenTelemetry](https://opentelemetry.io/) TraceID's to all log lines.
- [slogdedup](https://github.com/veqryn/slog-dedup): Middleware that deduplicates and sorts attributes. Particularly useful for JSON logging.
- [slogdedup](https://github.com/veqryn/slog-dedup): Middleware that deduplicates and sorts attributes. Particularly useful for JSON logging. Format logs for aggregators (Graylog, GCP/Stackdriver, etc).
- [slogbugsnag](https://github.com/veqryn/slog-bugsnag): Middleware that pipes Errors to [Bugsnag](https://www.bugsnag.com/).
- [slogjson](https://github.com/veqryn/slog-json): Formatter that uses the [JSON v2](https://github.com/golang/go/discussions/63397) [library](https://github.com/go-json-experiment/json), with optional single-line pretty-printing.

## Install
`go get github.com/veqryn/slog-bugsnag`
Expand Down
43 changes: 0 additions & 43 deletions json_tags.go

This file was deleted.

34 changes: 0 additions & 34 deletions json_tags_test.go

This file was deleted.

15 changes: 11 additions & 4 deletions log_to_bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"runtime"
"strings"
"time"

"github.com/bugsnag/bugsnag-go/v2"
Expand Down Expand Up @@ -119,8 +120,6 @@ func (h *Handler) logToBug(ctx context.Context, t time.Time, lvl slog.Level, msg
// Attribute values are redacted based on the notifier config ParamsFilters.
// accumulateRawData also finds the latest [error] and [bugsnag.User].
func (h *Handler) accumulateRawData(errForBugsnag *error, user *bugsnag.User, md bugsnag.MetaData, tab string, attrs []slog.Attr) {
san := sanitizer{Filters: h.notifiers.notifier.Config.ParamsFilters}

for _, attr := range attrs {
if attr.Value.Kind() == slog.KindGroup {
h.accumulateRawData(errForBugsnag, user, md, attr.Key, attr.Value.Group())
Expand Down Expand Up @@ -157,9 +156,17 @@ func (h *Handler) accumulateRawData(errForBugsnag *error, user *bugsnag.User, md

// Always resolve log attribute values
attr.Value = attr.Value.Resolve()
val := san.Sanitize(attr.Value.Any())
md.Add(tab, attr.Key, val)
md.Add(tab, attr.Key, attr.Value.Any())
}
}

func shouldRedact(key string, filters []string) bool {
for _, filter := range filters {
if strings.Contains(strings.ToLower(key), strings.ToLower(filter)) {
return true
}
}
return false
}

// bsSeverity converts a [slog.Level] to a [bugsnag.severity]
Expand Down
161 changes: 0 additions & 161 deletions metadata.go

This file was deleted.

Loading

0 comments on commit 6a3365e

Please sign in to comment.