Score:0

NGINX adds header multiple times falsely

pw flag

I want to add CORS to my reverse-proxy. Generally everything is working but I don't understand why even though reading the documentation on add_header and reading several forum entries.

In my case I have two ifs and I would assume that nginx only resolves one but I don't even understand what is happening. Because if Iam requesting the location, the preflight is fine but then the acutal request tells me:

CORS mutliple .. not allowed

And looking in the response headers there are actually two:

Responseheader

The location part follows (no these are the only calls of add_header Iam performing):

location / {
    # Preflighted requests
    if ($request_method ~* "(GET|PUT|POST|DELETE)" ) {
        add_header "Access-Control-Allow-Origin"  *;
        add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
        add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";

        proxy_pass http://<myservice>:91;
    }

    if ($request_method = OPTIONS ) {
        add_header "Access-Control-Allow-Origin"  *;
        add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
        add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
        return 200;
        }
    }
}

Though the funny part is, that despite having this error in the browser the payload is there and it is valid. So I can clearly deduce that these double origin thing is my problem. (Already got that and solved it but without getting why it works).

Thanks for help or clearing up my mind; I just want to get what kind of sorcery that is.

Richard Smith avatar
jp flag
Could the service on `<myservice>:91` also be adding a header?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.