base64 blob.decode() default error handling

pyunyh pyunyh at gmail.com
Mon Nov 4 02:32:07 UTC 2019


Hi,

In order to validate client supplied base64 encoded string I have a
VCL something like the following.

        if (blob.length(blob.decode(BASE64, 0, req.http.Sec-WebSocket-Key)) != 16) {
                return (synth(400, "Bad Request"));
        }

If the Sec-WebSocket-Key header has a badly encoded string VCL will
generate a "503 VCL failed" response. It's somewhat hard to generate
a 400 repsonse in this case, since very little thing can be done in
vcl_synth().  As you know resp.status can be overriden as well as
resp.reason in vcl_synth() but all state tracking made so far is
completely lost in vcl_synth() so there is no way to know where the
vcl_synth() is called from which context.
What is proper way to handle this case?
If there is a way to override arguments passed to synth() with
return(fail) during base64 decoding this will address the issue.
I think this can be easily solved with inline C but it it would be
better to have a VCL method as vcc_allow_inline_c is disabled by
default.

Thanks.


More information about the varnish-dev mailing list