Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
0bc19df6
Commit
0bc19df6
authored
Feb 02, 2015
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Made command HTTP API only accept requests from referers on the same server
parent
ae5259f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
http/handler.go
http/handler.go
+15
-0
No files found.
http/handler.go
View file @
0bc19df6
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"io"
"io"
"net/http"
"net/http"
"strconv"
"strconv"
"strings"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
@@ -55,6 +56,20 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -55,6 +56,20 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log
.
Debug
(
"Incoming API request: "
,
r
.
URL
)
log
.
Debug
(
"Incoming API request: "
,
r
.
URL
)
// error on external referers (to prevent CSRF attacks)
referer
:=
r
.
Referer
()
scheme
:=
r
.
URL
.
Scheme
if
len
(
scheme
)
==
0
{
scheme
=
"http"
}
host
:=
fmt
.
Sprintf
(
"%s://%s/"
,
scheme
,
r
.
Host
)
// empty string means the user isn't following a link (they are directly typing in the url)
if
referer
!=
""
&&
!
strings
.
HasPrefix
(
referer
,
host
)
{
w
.
WriteHeader
(
http
.
StatusForbidden
)
w
.
Write
([]
byte
(
"403 - Forbidden"
))
return
}
if
len
(
i
.
origin
)
>
0
{
if
len
(
i
.
origin
)
>
0
{
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
i
.
origin
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
i
.
origin
)
}
}
...
...
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