Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
10f4e822
Commit
10f4e822
authored
Aug 07, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add XSRFExpire
parent
b191e96f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
1 deletion
+13
-1
beego.go
beego.go
+2
-0
config.go
config.go
+3
-0
controller.go
controller.go
+8
-1
No files found.
beego.go
View file @
10f4e822
...
@@ -46,6 +46,7 @@ var (
...
@@ -46,6 +46,7 @@ var (
ErrorsShow
bool
//set weather show errors
ErrorsShow
bool
//set weather show errors
XSRFKEY
string
//set XSRF
XSRFKEY
string
//set XSRF
EnableXSRF
bool
EnableXSRF
bool
XSRFExpire
int
CopyRequestBody
bool
//When in raw application, You want to the reqeustbody
CopyRequestBody
bool
//When in raw application, You want to the reqeustbody
)
)
...
@@ -76,6 +77,7 @@ func init() {
...
@@ -76,6 +77,7 @@ func init() {
HttpServerTimeOut
=
0
HttpServerTimeOut
=
0
ErrorsShow
=
true
ErrorsShow
=
true
XSRFKEY
=
"beegoxsrf"
XSRFKEY
=
"beegoxsrf"
XSRFExpire
=
60
ParseConfig
()
ParseConfig
()
}
}
...
...
config.go
View file @
10f4e822
...
@@ -195,6 +195,9 @@ func ParseConfig() (err error) {
...
@@ -195,6 +195,9 @@ func ParseConfig() (err error) {
if
enablexsrf
,
err
:=
AppConfig
.
Bool
(
"enablexsrf"
);
err
==
nil
{
if
enablexsrf
,
err
:=
AppConfig
.
Bool
(
"enablexsrf"
);
err
==
nil
{
EnableXSRF
=
enablexsrf
EnableXSRF
=
enablexsrf
}
}
if
expire
,
err
:=
AppConfig
.
Int
(
"xsrfexpire"
);
err
==
nil
{
XSRFExpire
=
expire
}
}
}
return
nil
return
nil
}
}
controller.go
View file @
10f4e822
...
@@ -35,6 +35,7 @@ type Controller struct {
...
@@ -35,6 +35,7 @@ type Controller struct {
_xsrf_token
string
_xsrf_token
string
gotofunc
string
gotofunc
string
CruSession
session
.
SessionStore
CruSession
session
.
SessionStore
XSRFExpire
int
}
}
type
ControllerInterface
interface
{
type
ControllerInterface
interface
{
...
@@ -353,7 +354,13 @@ func (c *Controller) XsrfToken() string {
...
@@ -353,7 +354,13 @@ func (c *Controller) XsrfToken() string {
fmt
.
Fprintf
(
h
,
"%s:%d"
,
c
.
Ctx
.
Request
.
RemoteAddr
,
time
.
Now
()
.
UnixNano
())
fmt
.
Fprintf
(
h
,
"%s:%d"
,
c
.
Ctx
.
Request
.
RemoteAddr
,
time
.
Now
()
.
UnixNano
())
tok
:=
fmt
.
Sprintf
(
"%s:%d"
,
h
.
Sum
(
nil
),
time
.
Now
()
.
UnixNano
())
tok
:=
fmt
.
Sprintf
(
"%s:%d"
,
h
.
Sum
(
nil
),
time
.
Now
()
.
UnixNano
())
token
=
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
tok
))
token
=
base64
.
URLEncoding
.
EncodeToString
([]
byte
(
tok
))
c
.
Ctx
.
SetCookie
(
"_xsrf"
,
token
)
expire
:=
0
if
c
.
XSRFExpire
>
0
{
expire
=
c
.
XSRFExpire
}
else
{
expire
=
XSRFExpire
}
c
.
Ctx
.
SetCookie
(
"_xsrf"
,
token
,
expire
)
}
}
c
.
_xsrf_token
=
token
c
.
_xsrf_token
=
token
}
}
...
...
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