Welcome Guest, Not a member yet? Register   Sign In
File Upload Validation Broke
#13

(This post was last modified: 04-24-2020, 04:18 PM by Gary.)

Of course, one needs to get the Javascript to intercept it client-side too.

This is the after filter:
Code:
    public function after(RequestInterface $request, ResponseInterface $response) {
        $response->populateHeaders();
        $format = $response->getHeaderLine('content-type');
        if (strpos($format, 'html') === FALSE) {
            $body = $response->getBody();
            $body = sendCSRF().$body;
            $response->setBody($body);
        }
        return;
    }

And sendCSRF() is a simple custom helper function that produces the token with a termination marker the Javascript slices the (in my case) leading token off after:
Code:
function sendCSRF(string $string='') {
        return (csrf_hash().'XX-YOUR-CUSTOM-TOKEN-END-DEMARCATION-CHARS-XX'.$string);
    }

Currently it gets sent with all JavaScript responses, but it would be easy enough to customise, for example by which headers were on the outgoing response.

I use sendCSRF() elsewhere (which is why it has a string paramerter passed in, it can obviously be omitted).
Reply


Messages In This Thread
File Upload Validation Broke - by Gary - 04-12-2020, 11:51 AM
RE: File Upload Validation Broke - by Gary - 04-14-2020, 07:00 PM
RE: File Upload Validation Broke - by Gary - 04-23-2020, 02:06 PM
RE: File Upload Validation Broke - by Leo - 04-23-2020, 02:49 PM
RE: File Upload Validation Broke - by Gary - 04-23-2020, 03:18 PM
RE: File Upload Validation Broke - by Leo - 04-23-2020, 03:55 PM
RE: File Upload Validation Broke - by Gary - 04-24-2020, 08:47 AM
RE: File Upload Validation Broke - by Leo - 04-24-2020, 02:31 PM
RE: File Upload Validation Broke - by Gary - 04-24-2020, 03:03 PM
RE: File Upload Validation Broke - by Leo - 04-24-2020, 03:09 PM
RE: File Upload Validation Broke - by Gary - 04-24-2020, 03:40 PM
RE: File Upload Validation Broke - by Leo - 04-24-2020, 03:46 PM
RE: File Upload Validation Broke - by Gary - 04-24-2020, 03:58 PM
RE: File Upload Validation Broke - by Leo - 04-25-2020, 01:13 AM
RE: File Upload Validation Broke - by Leo - 04-25-2020, 02:56 AM
RE: File Upload Validation Broke - by Gary - 04-28-2020, 09:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB