Tuesday, June 19, 2012

Force google image search to use safe search with Dansguardian

I use dansguardian on my firewall at home to keep out offensive stuff from the Internet.
I downloaded blocklists a couple of years ago, and because it is mainly content based, I have adjusted it a little, but it still works very well.


It came with a set of regular expressions to force major search engines to use safe search when searching for images, but I noticed recently that some recent changes at google broke this feature.

 I got a new one working (it does catch all searches, and not just images. If someone were to narrow it to work on image and videos, feel free to post a comment)
In the process I noticed that there was nothing filtering bing searches, (heaven knows why one would use bing, but best to be thorough).
Also important is that this method helps with ssl encrypted searches, which are otherwise hard to block.

In the hope that this will be helpful to someone else:

add the following to /etc/dansguardian/lists/urlregexplist (it might be in a different folder, but the name of the file will be  urlregexplist)


#for google
#we add &safe=vss to the end of every search
 "(^http[s]?://[0-9a-z]+\.google\.[a-z]+[-/%.0-9a-z]*/search\?.*)"->"\1&safe=vss"


#for bing
#similar, but &adlt=strict is the keyword
"(http[s]?://[0-9a-z]+.bing.com/images/search\?.*)"->"\1&adlt=strict"

hope that helps!

4 comments:

  1. Thanks Joshua. I use Dans to filter the lab at my sons school, but since i have refreshed the proxy I have noticed that these regex don't seem to function anymore. Thumbnails pop up with all sorts of inappropriate content when you do an image search. Any ideas?

    ReplyDelete
  2. this works perfectly thank you!

    ReplyDelete
  3. Works great but if you manually remove the &safe=vss from the url, then the search happens unfiltered. At least, it does for me. :-(

    ReplyDelete
  4. I have noticed that the push for https everywhere is really hurting our ability to filter google. Other than some kind of man-in-the-middle attack, I don't know how to fix the problem of ssl encrypted connections.

    ReplyDelete