Skip to content

Instantly share code, notes, and snippets.

View ThijsFeryn's full-sized avatar

Thijs Feryn ThijsFeryn

View GitHub Profile
varnishtest "Redis VMOD and strings containing NULL chars"
shell {
python - <<EOF
import base64
import redis
b64 = 'X3NmMl9hdHRyaWJ1dGVzfGE6Mjp7czo1OiJsaWtlZCI7YTowOnt9czoxNDoiX3NlY3VyaXR5X21haW4iO3M6OTAzOiJDOjc0OiJTeW1mb255XENvbXBvbmVudFxTZWN1cml0eVxDb3JlXEF1dGhlbnRpY2F0aW9uXFRva2VuXFVzZXJuYW1lUGFzc3dvcmRUb2tlbiI6ODE1OnthOjM6e2k6MDtOO2k6MTtzOjQ6Im1haW4iO2k6MjthOjQ6e2k6MDtPOjQxOiJTeW1mb255XENvbXBvbmVudFxTZWN1cml0eVxDb3JlXFVzZXJcVXNlciI6Nzp7czo1MToiAFN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcVXNlclxVc2VyAHVzZXJuYW1lIjtzOjU6InRoaWpzIjtzOjUxOiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAcGFzc3dvcmQiO3M6NjA6IiQyeSQxMiQxaUVVNVJ0REZUQkptMGhocXpZR2NPamdSTFhXUGlPQjYzS2VFVVhNNXA5bFFLejlFeklUQyI7czo1MDoiAFN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcVXNlclxVc2VyAGVuYWJsZWQiO2I6MTtzOjYwOiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAYWNjb3VudE5vbkV4cGlyZWQiO2I6MTtzOjY0OiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxVc2VyXFVzZXIAY3JlZGVudGlhbHNOb25FeHBpcmVkIjtiOjE7czo1OToiAFN5bWZvbnlcQ29tcG9uZW50XFN
public function start(Request $request, AuthenticationException $authException = null)
{
$jwtPayload = $this->getJwtPayload($request->cookies->get('token'));
if(isset($jwtPayload['sub'])) {
return new Response("Don't wanna to this, really. The actual protected page should show up instead");
}
return new RedirectResponse($this->router->generate('login'));
}
@ThijsFeryn
ThijsFeryn / default.vcl
Created December 14, 2017 14:35
test 123
vcl 4.0;
import std;
backend default {
.host = "176.62.169.146" ;
.port = "80";
}
acl purge {
"127.0.0.1";
@ThijsFeryn
ThijsFeryn / drupalcon_jwt_varnish.vcl
Created September 27, 2017 20:02
VCL file that describes my JWT implementation in Varnish for Drupal. Part of my DrupalCon Vienna 2017 presentation.
vcl 4.0;
import std;
import var;
import cookie;
import digest;
acl internal {
"192.168.20.0"/24;
}
@ThijsFeryn
ThijsFeryn / .htaccess
Created September 18, 2017 11:22
Force HTTPS redirect for sites behind a reverse (caching) proxy that terminates SSL
SetEnvIf X-Forwarded-Proto "https" HTTPS=on
Header append Vary: X-Forwarded-Proto
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
@ThijsFeryn
ThijsFeryn / bzf.php
Last active July 28, 2017 09:55
Logic do add the date to the post of blauwzwartfans.be
function addDateBeforeFirstParagraph($content) {
if(!is_singular('post')) return $content;
$closing_p = '<p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
@ThijsFeryn
ThijsFeryn / bio_en.md
Last active August 2, 2021 07:53
Thijs Feryn's bio

Thijs Feryn is a "technical evangelist" at Varnish Software, the company behind the Varnish Cache open source technology. His goal is to bring technology to the people and people to technology. He focuses on bridging the gap between code and infrastructure. Thijs is a published author with O'Reilly and with Vulkan, he is also involved in many open source communities. He speaks, listens, writes, codes, teaches, blogs, vlogs, organizes and is above all very excited to speak at "your event name"

@ThijsFeryn
ThijsFeryn / Dockerfile
Last active July 4, 2017 11:08
Dockerized Hello NodeJS example to test Kubernetes
FROM node:6.9.2
EXPOSE 8080
COPY server.js .
CMD node server.js
@ThijsFeryn
ThijsFeryn / call_jwt.vcl
Last active February 13, 2017 09:58
Call the custom-defined JWT VCL procedure that checks the validity of a JSON Web Token. This VCL snippet requires vmod_digest and https://gist.github.com/ThijsFeryn/b745c42dbfa328d702b8dbba8777aee2
vcl 4.0;
import digest;
backend default {
.host = "localhost";
.port = "8080";
}
include "jwt.vcl";
@ThijsFeryn
ThijsFeryn / jwt.vcl
Created February 13, 2017 09:25
A custom VCL procedure that validates a JSON Web Token. This procedure can be called from within your other VCL logic. You will need to install vmod_digest to have the digest functions.
sub jwt {
if(req.http.cookie ~ "^([^;]+;[ ]*)*token=[^\.]+\.[^\.]+\.[^\.]+([ ]*;[^;]+)*$") {
set req.http.x-token = ";" + req.http.Cookie;
set req.http.x-token = regsuball(req.http.x-token, "; +", ";");
set req.http.x-token = regsuball(req.http.x-token, ";(token)=","; \1=");
set req.http.x-token = regsuball(req.http.x-token, ";[^ ][^;]*", "");
set req.http.x-token = regsuball(req.http.x-token, "^[; ]+|[; ]+$", "");
set req.http.tmpHeader = regsub(req.http.x-token,"token=([^\.]+)\.[^\.]+\.[^\.]+","\1");
set req.http.tmpTyp = regsub(digest.base64url_decode(req.http.tmpHeader),{"^.*?"typ"\s*:\s*"(\w+)".*?$"},"\1");