My requirement is to enable "secure" flag in one of the header called "_adminv2_session" but which contains a dynamic value. I was trying to enable the flag using the below configurations in nginx, but it'll create a new header with same name and assign value "/"
add_header Set-Cookie "_adminv2_session=/; HttpOnly; Secure";
But when I try without value, it gives errors,
add_header Set-Cookie "_adminv2_session; HttpOnly; Secure";
Can anyone help me on enable secure flag on the so called header in nginx ?
Screenshot of current status,
Thanks.
You might need to use proxy_cookie_path and add_header directives like this.
As far as I understood, you need to set your _adminv2_session variable value first, then to add Secure flag to your Set-Cookie header.
Also you can use directive more_set_headers from 3rd-party headers_more module to do you task in one directive.
more_set_headers 'Set-Cookie: $sent_http_set_cookie; HttpOnly; Secure';
Related
This is my first time experimenting with Varnish.
We noticed our CDN not doing any request coalescing, so as an experiment I'm allowed to try out Varnish.
However I can't seem to figure out how to modify the response headers when stale content is served.
Image the following vcl and all backend responses have max-age=60, public, s-maxage=600 as the cache-control directive.
sub vcl_backend_response {
set beresp.grace = 3600s;
return (deliver);
}
When I:
visit /foo
do a varnish soft purge and a subsequent CDN (hard) purge on /foo
visit /foo again
When visiting /foo for the second time I'll immediately get a (stale) response. However I don't want it to have the same cache-control directive anymore, because then my CDN will continue to serve this stale response for another 10 minutes.
Is it possible to change the cache-control directive for stale content to max-age=0, public, s-maxage=10?
Here's the VCL code you need to modify the Cache-Control header for stale content:
vcl 4.1;
sub vcl_deliver {
//set resp.http.x-ttl = obj.ttl;
//set resp.http.x-grace = obj.grace;
if(obj.ttl <= 0s && obj.grace > 0s ) {
set resp.http.Cache-Control = "max-age=0, public, s-maxage=10";
}
}
If you want to debug the process, just uncomment the 2 lines and look for the x-ttl and x-grace response headers to see the remaining values for both timers.
Although you can control the staleness by setting beresp.grace in VCL, you can also set the staleness through the stale-while-revalidate directive in the Cache-Control header.
Here's an example:
Cache-Control: max-age=60, public, s-maxage=600, stale-while-revalidate=3600
This will allow the browser to cache for a minute, allow intermediary servers to cache for 10 minutes and set an allowed staleness of an hour while revalidating outdated content.
We're currently using the s-maxage directive in the Cache-Control header from our origin to control the TTL in Varnish. However, I'd like to remove it from the response before delivery, so that no other caches in the request chain act on it.
I'm currently looking at the header VMOD, to remove s-maxage from the header, but leave the rest of it intact. I believe this could be achieved with something like this:
sub vcl_deliver {
header.regsub(resp, "s-maxage=[0-9]+,?\s?", "")
}
As a newcomer to Varnish, I wanted to sanity-check this approach and make sure there isn't a better way to tackle it?
Appreciate any support or advice.
Replace header at delivery time
The following VCL snippet will strip off the s-maxage attribute from the Cache-Control header before it is sent to the client.
sub vcl_deliver {
set resp.http.cache-control = regsub(resp.http.cache-control,
"(,\s*s-maxage=[0-9]+\s*$)|(\s*s-maxage=[0-9]+\s*,)","");
}
Replace header at storage time
It is also possible to strip off this attribute from the Cache-Control header before it gets stored into a cache object. In that case, you'll use the beresp.http.cache-control variable inside vcl_backend_response.
sub vcl_backend_response {
set beresp.http.cache-control = regsub(beresp.http.cache-control,
"(,\s*s-maxage=[0-9]+\s*$)|(\s*s-maxage=[0-9]+\s*,)","");
}
Using vmod_headerplus
If you're using Varnish Enterprise, you can use the vmod_headerplus module to easily delete header attributes:
vcl 4.1;
import headerplus;
sub vcl_deliver {
headerplus.init(resp);
headerplus.attr_delete("Cache-Control","s-maxage",",");
headerplus.write();
}
vcl 4.1;
import headerplus;
sub vcl_backend_response {
headerplus.init(beresp);
headerplus.attr_delete("Cache-Control","s-maxage",",");
headerplus.write();
}
Although Varnish Enterprise is the commercial version of Varnish Cache, you can still use it without upfront license payments if you use it on AWS, Azure or GCP.
Varnish Enterprise on AWS
Varnish Enterprise on Azure
Varnish Enterprise on GCP
As explained in https://web.dev/samesite-cookies-explained/, Chrome will enable SameSite=lax by default if SameSite is not specified.
In Apex, we can set Cookie using Cookie ck = new Cookie('cookieLabel','cookieValue',null,-1,false);
How can I set SameSite=None;Secure for ck variable of Cookie class?
As far as I can tell, the Apex Cookie Class does not support the SameSite attribute at all.
As a result, I would investigate using HttpResponse.setHeader() directly:
httpResponse.setHeader('Set-Cookie', 'cookieLabel=cookieValue; SameSite=None; Secure');
Be aware though, in other frameworks I do see the cookie handling overwrite any existing Set-Cookie headers so you may want to ensure you do any manual setting of headers either before or after the in-built cookie handling.
I would also raise a feature request for full support of the SameSite attribute in the framework.
I am able to add the below mentioned header via UI in IIS and other simple headers via command line (appcmd), but this one seems cryptic.. not able to get it. Throwing syntax errors whatever i try. Any help is appreciated ...
X-XSS-Protection
1; mode=block
Looks like i found it
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpProtocol /+"customHeaders.[name='X-XSS-Protection',value='1; mode=block']"
I'm trying to get CORS working on my trigger.io app:
I've got the following setup in my .htaccess
Header set Access-Control-Allow-Headers: "Accept,Origin,Content-Type,X-Requested-With"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE,OPTIONS"
Header set Access-Control-Allow-Credentials: "true"
Header set Access-Control-Allow-Origin "http://localhost:3000,content://io.trigger.forge99d5a0b8621e11e28cc2123139286d0c"
Running the trigger App in the web (localhost:3000) works fine.
But when I deploy it to an (android) device I see the following error in the debug output:
[ERROR] XMLHttpRequest cannot load {link}http://mydevtest.lan/api/auth/currentuser.{/link} Origin content://io.trigger.forge99d5a0b8621e11e28cc2123139286d0c is not allowed by Access-Control-Allow-Origin. -- From line 1 of null
I'm fearing that setting content:// in the Access-Control-Allow-Origin header is not legal.
The Access-Control-Allow-Origin header as you have it is invalid. Valid values are either '*', or a space separated list of origins. One of the following should work:
Header set Access-Control-Allow-Origin "*"
or
Header set Access-Control-Allow-Origin "http://localhost:3000 content://io.trigger.forge99d5a0b8621e11e28cc2123139286d0c"
Note that I've never tested the latter form (with multiple origins). While the CORS spec allows it, browsers may not yet support it.
One other thing you could do is read in the value of the Origin header, validate it on your server (i.e. manually check that the value equals either "http://localhost:3000" or "content://io.trigger.forge99d5a0b8621e11e28cc2123139286d0c"), and then echo only that value in the Access-Control-Allow-Origin response header. However this requires a little more work since it introduces some server-side conditional processing.
I also fear that content:// is not allowed in CORS, could you try setting Access-Control-Allow_origin to *, if that works then that is probably the problem.
A better solution would be to avoid doing XHR requests and use forge.request.ajax which will make the request from native code and avoid any cross domain restrictions. You can find the documentation for that here http://docs.trigger.io/en/v1.4/modules/request.html#modules-request