aws-samples / amazon-cloudfront-functions

Apache License 2.0
479 stars 78 forks source link

Using cloudfron functions to remove server header #25

Closed lpsm-dev closed 1 year ago

lpsm-dev commented 2 years ago

I currently have a cloudfront that responds with the path /login/<client-A> and I would like to remove the server header from the response. It's possible?

I tried this code:

function handler(event) {
    var response = event.response;
    var headers = response.headers;

    headers['x-content-type-options'] = { value: 'nosniff'}; 
    headers['x-frame-options'] = {value: 'DENY'}; 
    headers['x-xss-protection'] = {value: '1; mode=block'};
    headers['referrer-policy'] = {value:  #'same-origin'};
    headers['server'] = {value: '*'};

    return response;
}

But it only worked when I accessed the cloudfront from the root path /:

Screen Shot 2021-12-09 at 13 30 00

With the path /login/<client> I got the following result, but it's not what I want:

Screen Shot 2021-12-09 at 13 31 15

BilalAshfaq commented 2 years ago

@ci-monk Were you able to figure this out? I am facing the same issue.

lpsm-dev commented 1 year ago

@ci-monk Were you able to figure this out? I am facing the same issue.

Hi @BilalAshfaq!

I was able to resolve this through this documentation:

lpsm-dev commented 1 year ago

Resolved!