晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/akaindir/www/crm/libraries/csrf-magic/ |
Upload File : |
[[ csrf-magic ]]
Add the following line to the top of all web-accessible PHP pages. If you have
a common file included by everything, put it there.
include_once '/path/to/csrf-magic.php';
Do it, test it, then forget about it. csrf-magic is protecting you if nothing
bad happens. Read on if you run into problems.
TABLE OF CONTENTS
+ ------------------- +
1. TIPS AND TRICKS
2. AJAX
3. CONFIGURE
4. THANKS
5. FOOTNOTES
+ ------------------- +
1. TIPS AND TRICKS
* If your JavaScript and AJAX is persistently getting errors, check the
AJAX section below on how to fix.
* The CSS overlay protection makes it impossible to display your website
in frame/iframe elements. You can disable it with
csrf_conf('frame-breaker', false) in your csrf_startup() function.
* csrf-magic will start a session. To disable, use csrf_conf('auto-session',
false) in your csrf_startup() function.
* The default error message is a little user unfriendly. Write your own
function which outputs an error message and set csrf_conf('callback',
'myCallbackFunction') in your csrf_startup() function.
* Make sure csrf_conf('secret', 'ABCDEFG') has something random in it. If
the directory csrf-magic.php is in is writable, csrf-magic will generate
a secret key for you in the csrf-secret.php file.
* Remember you can use auto_prepend to include csrf-magic.php on all your
pages. You may want to create a stub file which you can include that
includes csrf-magic.php as well as performs configuration.
* The default expiration time for tokens is two hours. If you expect your
users to need longer to fill out forms, be sure to enable double
submission when the token is invalid.
2. AJAX
csrf-magic has the ability to dynamically rewrite AJAX requests which use
XMLHttpRequest. However, due to the invasiveness of this procedure, it is
not enabled by default. You can enable it by adding this code before you
include csrf-magic.php.
function csrf_startup() {
csrf_conf('rewrite-js', '/web/path/to/csrf-magic.js');
}
// include_once '/path/to/csrf-magic.php';
(Be sure to place csrf-magic.js somewhere web accessible).
The default method CSRF Magic uses to rewrite AJAX requests will
only work for browsers with support for XmlHttpRequest.prototype (this excludes
all versions of Internet Explorer). See this page for more information:
http://stackoverflow.com/questions/664315/internet-explorer-8-prototypes-and-xmlhttprequest
However, csrf-magic.js will
automatically detect and play nice with the following JavaScript frameworks:
* jQuery
* Prototype
* MooTools
* Ext
* Dojo
(Note 2013-07-16: It has been a long time since this manual support has
been updated, and some JavaScript libraries have placed their copies of XHR
in local variables in closures, which makes it difficult for us to monkey-patch
it in automatically.)
To rewrite your own JavaScript library to use csrf-magic.js, you should modify
your function that generates XMLHttpRequest to have this at the end:
return new CsrfMagic(xhrObject);
With whatever xhrObject may be. If you have literal instances of XMLHttpRequest
in your code, find and replace ''new XMLHttpRequest'' with ''new CsrfMagic''
(CsrfMagic will automatically instantiate an XMLHttpRequest object in a
cross-platform manner as necessary).
If you don't want csrf-magic monkeying around with your XMLHttpRequest object,
you can manually rewrite your AJAX code to include the variable. The important
information is stored in the global variables csrfMagicName and csrfMagicToken.
CsrfMagic.process may also be of interest, as it takes one parameter, a
querystring, and prepends the CSRF token to the value.
3. CONFIGURE
csrf-magic has some configuration options that you can set inside the
csrf_startup() function. They are described in csrf-magic.php, and you can
set them using the convenience function csrf_conf($name, $value).
For example, this is a recommended configuration:
/**
* This is a function that gets called if a csrf check fails. csrf-magic will
* then exit afterwards.
*/
function my_csrf_callback() {
echo "You're doing bad things young man!";
}
function csrf_startup() {
// While csrf-magic has a handy little heuristic for determining whether
// or not the content in the buffer is HTML or not, you should really
// give it a nudge and turn rewriting *off* when the content is
// not HTML. Implementation details will vary.
if (isset($_POST['ajax'])) csrf_conf('rewrite', false);
// This is a secret value that must be set in order to enable username
// and IP based checks. Don't show this to anyone. A secret id will
// automatically be generated for you if the directory csrf-magic.php
// is placed in is writable.
csrf_conf('secret', 'ABCDEFG123456');
// This enables JavaScript rewriting and will ensure your AJAX calls
// don't stop working.
csrf_conf('rewrite-js', '/csrf-magic.js');
// This makes csrf-magic call my_csrf_callback() before exiting when
// there is a bad csrf token. This lets me customize the error page.
csrf_conf('callback', 'my_csrf_callback');
// While this is enabled by default to boost backwards compatibility,
// for security purposes it should ideally be off. Some users can be
// NATted or have dialup addresses which rotate frequently. Cookies
// are much more reliable.
csrf_conf('allow-ip', false);
}
// Finally, include the library
include_once '/path/to/csrf-magic.php';
Configuration gets stored in the $GLOBALS['csrf'] array.
4. THANKS
My thanks to Chris Shiflett, for unintentionally inspiring the idea, as well
as telling me the original variant of the Bob and Mallory story,
and the Django CSRF Middleware authors, who thought up of this before me.
Gareth Heyes suggested using the frame-breaker option to protect against
CSS overlay attacks.