-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Open csp-images to allow external (#1835)
External images are required for the README parts of templates. Only allowing https right now
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package coderd | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/coder/coder/coderd/httpapi" | ||
|
||
"cdr.dev/slog" | ||
) | ||
|
||
type cspViolation struct { | ||
Report map[string]interface{} `json:"csp-report"` | ||
} | ||
|
||
// logReportCSPViolations will log all reported csp violations. | ||
func (api *API) logReportCSPViolations(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
var v cspViolation | ||
|
||
dec := json.NewDecoder(r.Body) | ||
err := dec.Decode(&v) | ||
if err != nil { | ||
api.Logger.Warn(ctx, "csp violation", slog.Error(err)) | ||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{ | ||
Message: "failed to read body", | ||
}) | ||
return | ||
} | ||
|
||
fields := make([]slog.Field, 0, len(v.Report)) | ||
for k, v := range v.Report { | ||
fields = append(fields, slog.F(k, v)) | ||
} | ||
api.Logger.Warn(ctx, "csp violation", fields...) | ||
|
||
httpapi.Write(rw, http.StatusOK, "ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters