Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
c07b4a57
Unverified
Commit
c07b4a57
authored
Dec 23, 2022
by
boojack
Committed by
GitHub
Dec 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add secure middleware (#832)
parent
dca35bde
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
6 deletions
+5
-6
resource.go
server/resource.go
+1
-6
server.go
server/server.go
+4
-0
No files found.
server/resource.go
View file @
c07b4a57
...
...
@@ -7,7 +7,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/usememos/memos/api"
...
...
@@ -263,11 +262,7 @@ func (s *Server) registerResourcePublicRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to fetch resource ID: %v"
,
resourceID
))
.
SetInternal
(
err
)
}
if
strings
.
HasPrefix
(
resource
.
Type
,
echo
.
MIMETextHTML
)
{
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
"Content-Type"
,
echo
.
MIMETextPlain
)
}
else
{
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
"Content-Type"
,
resource
.
Type
)
}
c
.
Response
()
.
Writer
.
WriteHeader
(
http
.
StatusOK
)
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
echo
.
HeaderCacheControl
,
"max-age=31536000, immutable"
)
if
_
,
err
:=
c
.
Response
()
.
Writer
.
Write
(
resource
.
Blob
);
err
!=
nil
{
...
...
server/server.go
View file @
c07b4a57
...
...
@@ -44,6 +44,10 @@ func NewServer(profile *profile.Profile) *Server {
Timeout
:
30
*
time
.
Second
,
}))
e
.
Use
(
middleware
.
SecureWithConfig
(
middleware
.
SecureConfig
{
ContentSecurityPolicy
:
"default-src 'self'"
,
}))
embedFrontend
(
e
)
// In dev mode, set the const secret key to make signin session persistence.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment