Skip to content

Commit

Permalink
Allows Anonymous Downloads of Shared Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs committed Jan 24, 2024
1 parent 3528656 commit 3e734e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ type allowFn func(r *http.Request) bool

var publicEndpoints = []allowFn{
allowPublicInitiativeLookups,
allowPublicAnalysisDownloads,
}

var allowPublicInitiativeLookupsRegexp = regexp.MustCompile(`^/initiative/[^/]*$`)
Expand All @@ -388,6 +389,15 @@ func allowPublicInitiativeLookups(r *http.Request) bool {
return allowPublicInitiativeLookupsRegexp.MatchString(r.URL.Path)
}

var allowPublicAnalysisDownloadsRegexp = regexp.MustCompile(`^/report/.*$`)

func allowPublicAnalysisDownloads(r *http.Request) bool {
if r.Method != http.MethodGet {
return false
}
return allowPublicAnalysisDownloadsRegexp.MatchString(r.URL.Path)
}

func requireJWTIfNotPublicEndpoint(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for _, fn := range publicEndpoints {
Expand Down
1 change: 1 addition & 0 deletions reportsrv/reportsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (s *Server) doAuthzAndAuditLog(a *pacta.Analysis, aa *pacta.AnalysisArtifac
actorID, _ := session.UserIDFromContext(ctx)
if actorID == "" {
actorID = unauthenticatedUserID
actorOwner = &pacta.Owner{ID: unauthenticatedUserID}
} else {
ownerID, err := s.db.GetOwnerForUser(s.db.NoTxn(ctx), actorID)
if err != nil {
Expand Down

0 comments on commit 3e734e2

Please sign in to comment.