开发者

Trying to tell the difference between a bad resource link and a random bad url from outside the site

I'm trying to make my exception notification a bit smarter. Currently, if i have a bad resource link such as a misnamed javascript file referred to in a file link tag, it triggers a "No route matches" error. I also get a "No route matches" error if someone just types some random url (eg when trying to hack the site). I'm trying to tell the difference between these two kinds of "no route matches" errors, so i can send a 'something broke' email in the first case and a 'someone tried to hack the site' email in the second case.

I thought that i would be able to do that by looking at request.referer, thinking that, in the case where one of my pages has a link to a non-existent file, that the referer would be my site.

This works for page links: ie, if one of my pages has a link to a page that doesn't exist, then request.ref开发者_运维百科erer comes through as the page with the bad link, and so i know that it's a genuine error inside the site. But, for links to assets such as stylesheets, javascript files and images, it comes through as nil, same as it does if someone makes some random request from outside the site. So, i can't tell the difference.

I'm seeing this in development mode, where all the file links just point to localhost:3000 - on my server i use the assets0 -> assets3 trick to make the browser think that it's pulling files from four different servers. I just mention this in case it makes things more complicated.

How can i tell the difference? Grateful for any advice - max


Hmm - interesting idea!

One (rather hacky) option would be to have a set of catch-alls at the bottom of routes.rb for routes that you know are almost right eg (note not tested):

"/public/javascripts/:scriptname" => :controller => "Application", :action => "broken_script_link"

it's a bit yuck, but anything you catch with that would then be loggable as something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜