I created a Node.js based web application, running in an Azure Web App, that I wanted to put behind an Azure Active Directory authentication. After activating "App Service Authentication" as described on this page, the login process works normally, however upon returning to my app, it just returns a HTTP 431 "Request Header Fields Too Large".
To validate it's not my app, I checked the Azure web app sample for Node.js and even this returns a 431 when activating AAD.
Steps to reproduce:
Result: When opening the web app URL with a browser, it will show the log in process, following the process everything seems to work fine and the AAD returns to the application, however at that point it returns a HTTP 431.
Further tests:
Any ideas? Am I missing something?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Quick update: I now did a clean run of the "Create a Node.js app in Azure" page (https://docs.microsoft.com/en-us/azure/app-service/containers/quickstart-nodejs), which worked without authentication.
After activating AAD authentication as described, this app also returns a 431 error.
Hi @DirkSonguer, thank you for the detailed question! We are currently investigating and will update you when we have accurate information to provide.
Quick update: Creating a new Web App and activating app service authentication with the default web page works as described. The issue seems to be that as soon as a Node.js web service / server comes in (as described in the docs), it doesn't work anymore as the service returns the respective HTTP 431 error.
Looking through the logs, the authentication seems to indeed work fine with the Node.js service:
2020-04-06T09:41:00 PID[17788] Verbose JWT validation succeeded. Subject: '...', Issuer:'https://sts.windows.net/.../'.
2020-04-06T09:41:00 PID[17788] Verbose Calling into external HTTP endpoint POST https://login.windows.net/.../oauth2/token.
2020-04-06T09:41:01 PID[17788] Information Login completed for '[email protected]'. Provider: 'aad'.
2020-04-06T09:41:01 PID[17788] Verbose Writing 'AppServiceAuthSession' cookie for site'my-web-app.azurewebsites.net'. Length: 1112.
2020-04-06T09:41:01 PID[17788] Information Redirecting: https://my-web-app.azurewebsites.net/
2020-04-06T09:41:01 PID[17788] Verbose Received request: GET https://my-web-app.azurewebsites.net/
2020-04-06T09:41:01 PID[17788] Verbose Received request: GET https://my-web-app.azurewebsites.net/
2020-04-06T09:41:01 PID[17788] Verbose Found 'AppServiceAuthSession' cookie for site 'my-web-app.azurewebsites.net'. Length: 1112.
2020-04-06T09:41:01 PID[17788] Verbose Authenticated [email protected] successfully using 'Session Cookie' authentication.
The cookie with length 1112 also doesn't seem to be outlandishly large and the referrer URL also seems fine. At this point it seems like everything should work with Node.js, but doesn't.
Any update on this?
I did some more tests on my side. Turns out if you follow the steps with a Web App running on West EU, it works as described in the docs:
Result: Works as intended
However keeping Central US as default location when creating the Web App and following the same steps led to the error described above.
At this point I personally have no idea how to test / debug this further.
TLDR: Add key "WEBSITE_AUTH_DISABLE_IDENTITY_FLOW", value "true" to Configuration -> Application Settings to filter the large requests.
I am still encountering this error on a fresh node.js app with authentication turned on. I have set WEBSITE_AUTH_DISABLE_IDENTITY_FLOW to true, and even tried creating the app in West Europe, and I'm still getting 431 errors when navigating back to the app when I have a session already active.
Are there any additional workarounds I should try?
We are sorry you're experiencing this issue @teamstap100. Can you open a new issue so we can track and investigate this problem separately?
Most helpful comment
Solved: https://stackoverflow.com/questions/61059648/azure-web-app-node-js-azure-ad-error-431/61116561#61116561
TLDR: Add key "WEBSITE_AUTH_DISABLE_IDENTITY_FLOW", value "true" to Configuration -> Application Settings to filter the large requests.