Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Kulya
OpnSense
Commits
ab1ad19c
Commit
ab1ad19c
authored
Sep 12, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
csrf: no, JavaScript got trashed by script :(
parent
baebbe29
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
54 deletions
+35
-54
csrf-magic.js
src/www/csrf/csrf-magic.js
+35
-54
No files found.
src/www/csrf/csrf-magic.js
View file @
ab1ad19c
...
...
@@ -8,28 +8,16 @@
// Here are the basic overloaded method definitions
// The wrapper must be set BEFORE onreadystatechange is written to, since
// a bug in ActiveXObject prevents us from properly testing for it.
CsrfMagic
=
function
(
real
)
{
CsrfMagic
=
function
(
real
)
{
// try to make it ourselves, if you didn't pass it
if
(
!
real
)
{
try
{
real
=
new
XMLHttpRequest
;
}
}
catch
(
e
)
{
;}
if
(
!
real
)
{
try
{
real
=
new
ActiveXObject
(
'
Msxml2.XMLHTTP
'
);
}
}
catch
(
e
)
{
;}
if
(
!
real
)
{
try
{
real
=
new
ActiveXObject
(
'
Microsoft.XMLHTTP
'
);
}
}
catch
(
e
)
{
;}
if
(
!
real
)
{
try
{
real
=
new
ActiveXObject
(
'
Msxml2.XMLHTTP.4.0
'
);
}
}
catch
(
e
)
{
;}
if
(
!
real
)
try
{
real
=
new
XMLHttpRequest
;
}
catch
(
e
)
{;}
if
(
!
real
)
try
{
real
=
new
ActiveXObject
(
'
Msxml2.XMLHTTP
'
);
}
catch
(
e
)
{;}
if
(
!
real
)
try
{
real
=
new
ActiveXObject
(
'
Microsoft.XMLHTTP
'
);
}
catch
(
e
)
{;}
if
(
!
real
)
try
{
real
=
new
ActiveXObject
(
'
Msxml2.XMLHTTP.4.0
'
);
}
catch
(
e
)
{;}
this
.
csrf
=
real
;
// properties
var
csrfMagic
=
this
;
real
.
onreadystatechange
=
function
()
{
real
.
onreadystatechange
=
function
()
{
csrfMagic
.
_updateProps
();
return
csrfMagic
.
onreadystatechange
?
csrfMagic
.
onreadystatechange
()
:
null
;
};
...
...
@@ -38,23 +26,19 @@ CsrfMagic = function (real) {
CsrfMagic
.
prototype
=
{
open
:
function
(
method
,
url
,
async
,
username
,
password
)
{
if
(
method
==
'
POST
'
)
{
this
.
csrf_isPost
=
true
;
}
open
:
function
(
method
,
url
,
async
,
username
,
password
)
{
if
(
method
==
'
POST
'
)
this
.
csrf_isPost
=
true
;
// deal with Opera bug, thanks jQuery
if
(
username
)
{
return
this
.
csrf_open
(
method
,
url
,
async
,
username
,
password
);
}
else
{
return
this
.
csrf_open
(
method
,
url
,
async
);
}
if
(
username
)
return
this
.
csrf_open
(
method
,
url
,
async
,
username
,
password
);
else
return
this
.
csrf_open
(
method
,
url
,
async
);
},
csrf_open
:
function
(
method
,
url
,
async
,
username
,
password
)
{
if
(
username
)
{
return
this
.
csrf
.
open
(
method
,
url
,
async
,
username
,
password
);
}
else
{
return
this
.
csrf
.
open
(
method
,
url
,
async
);
}
csrf_open
:
function
(
method
,
url
,
async
,
username
,
password
)
{
if
(
username
)
return
this
.
csrf
.
open
(
method
,
url
,
async
,
username
,
password
);
else
return
this
.
csrf
.
open
(
method
,
url
,
async
);
},
send
:
function
(
data
)
{
if
(
!
this
.
csrf_isPost
)
{
return
this
.
csrf_send
(
data
);
}
send
:
function
(
data
)
{
if
(
!
this
.
csrf_isPost
)
return
this
.
csrf_send
(
data
);
prepend
=
csrfMagicName
+
'
=
'
+
csrfMagicToken
+
'
&
'
;
if
(
this
.
csrf_purportedLength
===
undefined
)
{
this
.
csrf_setRequestHeader
(
"
Content-length
"
,
this
.
csrf_purportedLength
+
prepend
.
length
);
...
...
@@ -63,11 +47,11 @@ CsrfMagic.prototype = {
delete
this
.
csrf_isPost
;
return
this
.
csrf_send
(
prepend
+
data
);
},
csrf_send
:
function
(
data
)
{
csrf_send
:
function
(
data
)
{
return
this
.
csrf
.
send
(
data
);
},
setRequestHeader
:
function
(
header
,
value
)
{
setRequestHeader
:
function
(
header
,
value
)
{
// We have to auto-set this at the end, since we don't know how long the
// nonce is when added to the data.
if
(
this
.
csrf_isPost
&&
header
==
"
Content-length
"
)
{
...
...
@@ -76,23 +60,23 @@ CsrfMagic.prototype = {
}
return
this
.
csrf_setRequestHeader
(
header
,
value
);
},
csrf_setRequestHeader
:
function
(
header
,
value
)
{
csrf_setRequestHeader
:
function
(
header
,
value
)
{
return
this
.
csrf
.
setRequestHeader
(
header
,
value
);
},
abort
:
function
()
{
abort
:
function
()
{
return
this
.
csrf
.
abort
();
},
getAllResponseHeaders
:
function
()
{
getAllResponseHeaders
:
function
()
{
return
this
.
csrf
.
getAllResponseHeaders
();
},
getResponseHeader
:
function
(
header
)
{
getResponseHeader
:
function
(
header
)
{
return
this
.
csrf
.
getResponseHeader
(
header
);
}
// ,
}
// proprietary
CsrfMagic
.
prototype
.
_updateProps
=
function
()
{
CsrfMagic
.
prototype
.
_updateProps
=
function
()
{
this
.
readyState
=
this
.
csrf
.
readyState
;
if
(
this
.
readyState
==
4
)
{
this
.
responseText
=
this
.
csrf
.
responseText
;
...
...
@@ -101,23 +85,20 @@ CsrfMagic.prototype._updateProps = function () {
this
.
statusText
=
this
.
csrf
.
statusText
;
}
}
CsrfMagic
.
process
=
function
(
base
)
{
CsrfMagic
.
process
=
function
(
base
)
{
var
prepend
=
csrfMagicName
+
'
=
'
+
csrfMagicToken
;
if
(
base
)
{
return
prepend
+
'
&
'
+
base
;
}
if
(
base
)
return
prepend
+
'
&
'
+
base
;
return
prepend
;
}
// callback function for when everything on the page has loaded
CsrfMagic
.
end
=
function
()
{
CsrfMagic
.
end
=
function
()
{
// This rewrites forms AGAIN, so in case buffering didn't work this
// certainly will.
forms
=
document
.
getElementsByTagName
(
'
form
'
);
for
(
var
i
=
0
;
i
<
forms
.
length
;
i
++
)
{
form
=
forms
[
i
];
if
(
form
.
method
.
toUpperCase
()
!==
'
POST
'
)
{
continue
;
}
if
(
form
.
elements
[
csrfMagicName
])
{
continue
;
}
if
(
form
.
method
.
toUpperCase
()
!==
'
POST
'
)
continue
;
if
(
form
.
elements
[
csrfMagicName
])
continue
;
var
input
=
document
.
createElement
(
'
input
'
);
input
.
setAttribute
(
'
name
'
,
csrfMagicName
);
input
.
setAttribute
(
'
value
'
,
csrfMagicToken
);
...
...
@@ -151,7 +132,7 @@ if (window.XMLHttpRequest && window.XMLHttpRequest.prototype && '\v' != 'v') {
// jQuery didn't implement a new XMLHttpRequest function, so we have
// to do this the hard way.
jQuery
.
csrf_ajax
=
jQuery
.
ajax
;
jQuery
.
ajax
=
function
(
s
)
{
jQuery
.
ajax
=
function
(
s
)
{
if
(
s
.
type
&&
s
.
type
.
toUpperCase
()
==
'
POST
'
)
{
s
=
jQuery
.
extend
(
true
,
s
,
jQuery
.
extend
(
true
,
{},
jQuery
.
ajaxSettings
,
s
));
if
(
s
.
data
&&
s
.
processData
&&
typeof
s
.
data
!=
"
string
"
)
{
...
...
@@ -159,13 +140,13 @@ if (window.XMLHttpRequest && window.XMLHttpRequest.prototype && '\v' != 'v') {
}
s
.
data
=
CsrfMagic
.
process
(
s
.
data
);
}
return
jQuery
.
csrf_ajax
(
s
);
return
jQuery
.
csrf_ajax
(
s
);
}
}
if
(
window
.
Prototype
)
{
// This works for script.aculo.us too
Ajax
.
csrf_getTransport
=
Ajax
.
getTransport
;
Ajax
.
getTransport
=
function
()
{
Ajax
.
getTransport
=
function
()
{
return
new
CsrfMagic
(
Ajax
.
csrf_getTransport
());
}
}
...
...
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