| 1 |
|
| MODULE = Punk PACKAGE = Punk::CSRF |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| # The two hooks the `csrf` keyword makes the compiler install (punk_csrf.h). |
| 6 |
|
| # lib/Punk/CSRF.pm is documentation. |
| 7 |
|
| |
| 8 |
|
| # before_dispatch: a reference return short-circuits the request, so a refusal |
| 9 |
|
| # answers 403 before any guard or handler runs. Returning nothing lets the |
| 10 |
|
| # request through - and, on the way, spends the token it arrived with. |
| 11 |
|
| void |
| 12 |
|
| _check(c) |
| 13 |
|
| SV *c |
| 14 |
|
| PPCODE: |
| 15 |
|
| { |
| 16 |
89 |
| SV *refused = pcf_check(aTHX_ c); |
| 17 |
|
| /* pcf_check ran Perl (the session load, $req->form, on_error), and |
| 18 |
|
| * Perl may have grown and so moved the value stack */ |
| 19 |
89 |
| SP = PL_stack_base + ax - 1; |
| 20 |
89 |
▶ | if (refused) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (refused) { |
32 |
57 |
89 |
|
| 21 |
32 |
▶ | EXTEND(SP, 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); |
0 |
32 |
32 |
|
| 22 |
32 |
| mPUSHs(refused); |
| 23 |
32 |
| XSRETURN(1); |
| 24 |
|
| } |
| 25 |
57 |
| XSRETURN_EMPTY; |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
|
| # after_dispatch: mirror the token into a script-readable cookie when it |
| 29 |
|
| # changed. Pushed after the session write-back, so both cookies go out on the |
| 30 |
|
| # same response. |
| 31 |
|
| SV * |
| 32 |
|
| _writeback(c, resp) |
| 33 |
|
| SV *c |
| 34 |
|
| SV *resp |
| 35 |
|
| CODE: |
| 36 |
89 |
| pcf_writeback(aTHX_ c, resp); |
| 37 |
89 |
| RETVAL = newSVsv(resp); |
| 38 |
|
| OUTPUT: |
| 39 |
|
| RETVAL |