We have a site with millions of users developed using Yii 1.1, few users reported HTTP 400 when they interact with any link on the site.When we try to reproduce the the issue for the same user in our local development system, it works just fine for us.
When we checked the app log, it appears to be have users land on view page our item without the item Id missed out that causes 400 in one scenario.
I verified the referrer Urls and checked all the statements that redirects users to item controller, all of them have second param passed array with ‘id’ key present. Even if ‘id’ sets as null value, it should have generated 404, not 400. There are possibilities for the CController::createUrl() would have skipped the param, but Url manager is not configured at all in the app which means, urlFormat is get and no rules to consider when composing url from route.
This is one use case I observed, but for few other users every link they clicked land on our site raises HTTP 400 which makes me clueless. I tried with old browsers / new browsers for the same user, but I couldn’t reproduce any.
Noted:
CSRF token is disabled
UrlManger not configured (so default are assumed)
Rights extension is enabled.
The other thing that I have observed is, urls appear to be case insensitive, though I haven’t configured UrlManger at all. I’m not sure whether this has anything to do with 400, but I wanted to add.
Platform:
NGINX 1.0.14
PHP-FPM 5.4.22 w/XCache v1.3.2
MySQL 5.5.21
If anyone can shed some light on where to look for this issue, it would be helpful.
Thanks for the response. Please find the stack trace from the log file. In the Item/train action, I verified all the methods that redirects to view action and ensure that none of them can skip the Id param. I also done the same in the view/item/train.php view file.
But, somehow the Url get generated with out id param that leads to 400. I couldn’t deduce anything from this log.
Is it UrlManager component that throws exception.
Or it is rights component that generates 400.
How can I even reproduce this error in my system?
How the URL works with both cases while Urls are case sensitive by default?
The app has SSO integrated with Open source forum. Is it failed SSO session / expired session that causes the problem?
Is that wrong HTTP verb that causes the the Id param to skip and generate 400. I have no clue. I don’t have idea of where to start debugging. I have added Yii2 port of debug extension to get more details / insight of the data at the time of exception.
Please advise me on what code should I share so you can help me.
Thank you for all the helps. It took me around 7 days to identify the issue. Though I’m an amateur programmer, my experience on identifying the issue may help someone.
Application log was not enabled. runtime didn’t have proper permission to write the logs. I fixed it to have the errors logged.
The original stack trace was not sufficient to identify the route cause. I had to install this extension (https://github.com/zhuravljov/yii2-debug) to get more insights in the issue (Is it happening to specific user agents, specific time, etc)
I already did the basic checks about case sensitivity, action param binding, routes, but all they were good.
When I checked the debug log, 400 raised as soon they interact with a particular page and that too in 1 second. When I did the same, it never occurred to me.
I shared my findings with the original developer, that it’s very unlikely for the user to click on any link for the system to generate 400. I couldn’t find HTTP 302 before 400, so it is unlikely to generate from server.
When I started debugging, there was a Tour (Bootstrap) plugin that I always skipped when attempting to reproduce the issue. That was causing all sort of issues. Whenever I search for problematic code, I skipped the public dir (Yii2 style), and looked into protected dir alone.
7 He suggested me to check the library, there the url was hard-coded. Users, whoever guided through the tour encountered the issue. Most users skipped the tour (like mine) so it affected only few users.
I started reading the following two books to improve my debugging skills.