Skip to content
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

Allows Anonymous Downloads of Shared Assets #171

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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/.*$`)
gbdubs marked this conversation as resolved.
Show resolved Hide resolved

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}
gbdubs marked this conversation as resolved.
Show resolved Hide resolved
} else {
ownerID, err := s.db.GetOwnerForUser(s.db.NoTxn(ctx), actorID)
if err != nil {
Expand Down
Loading