1 2 Previous Next 14 Replies Latest reply on Apr 10, 2012 6:48 AM by ianl

    YouTube Enforce Safety Mode Ruleset

    jebeling

      Attached are 2 rulesets for enforcing YouTube Safety mode. The zip files contain the ruleset, a custom blockpage and a README describing the installation steps. v4 is an advanced version of a simpler v2 ruleset that I originally developed based on a request from another SE. The nice thing about the v4 ruleset is that it gracefully handles situations where cookies are blocked. The ruleset would be much simpler without these features, but they do show off some of the cool features of MWG7 that newer users may not have been exposed to previously.

       

      Rule Sets
      YouTube Enforce Safety Mode v4
      [Ruleset for enforcing YouTube Safety mode. Only applies to hostnames that match in the YouTube Hosts wildcard list. Note that cookies must be enabled for youtube.com, otherwiseattempted access to any video will be blocked.]
      Enabled
      Applies to Requests: True / Responses: True / Embedded Objects: True
      1: URL.Host matches in list YouTube Hosts
      EnabledRuleActionEventsComments
      EnabledAllow Set Safety Mode Requests
      1: URL.Path equals "/set_safety_mode"
      2: AND URL.GetParameter("safety_mode") equals "true"
      Stop Rule SetAllow Set Safety Mode
      EnabledBlock Disable Safety Mode
      1: URL.Path equals "/set_safety_mode"
      2: AND URL.GetParameter("safety_mode") does not equal "true"
      Block<YouTube Safety Mode Block>Statistics.Counter.Increment("BlockedByURLFilter",1)<Default>Block if attempt to disable safety mode
      EnabledAllow Any YouTube Requests with Safety Mode Cookie Set
      1: Header.Request.Exists("Cookie") equals true
      2: AND Header.Request.Get("Cookie") matches in list You Tube Safety Cookie
      Stop Rule SetAny requests that have a cookie for safety mode already set are allowed
      Handle YouTube Responses When No Safety Cookie
      [This ruleset handles the responses when SM cookie doesn't exist. Or we haven't yet detected Safety mode on. In these cases we need to enable HTML Opener to look at Embedded Objects. This ruleset provides additional guidance to the user if cookies are blocked and will support Safety Mode when YouTube finally figures out how to do it by session server side.]
      Enabled
      Applies to Requests: False / Responses: True / Embedded Objects: True
      1: Header.Request.Get("Cookie") does not match in list You Tube Safety Cookie
      2: AND User-Defined.YouTube-SafetyMode-On equals false
      EnabledRuleActionEventsComments
      EnabledEnable HTML Opener
      Always
      ContinueEnable HTML Opener<YouTube Safety Mode Opener>
      Examine Safety Mode Hyperlink in Page Footer
      [If the footer says that Safety Mode is off, the page should be blocked. If we find that safety mode is on, set the UDP for the rest of the transaction]
      Enabled
      Applies to Requests: True / Responses: False / Embedded Objects: True
      1: HTMLElement.HasAttribute("onclick") equals true
      2: AND HTMLElement.Attribute("onclick") matches *safetymode-picker*
      3: AND URL.Path does not match in list YouTube Path List No Safety Mode
      EnabledRuleActionEventsComments
      EnabledIf Safety Mode is Off and Cookies are Enabled Redirect
      1: Body.ToString(0,Body.Size) matches *Off*
      2: AND Header.Request.Exists("Cookie") equals true
      Redirect<YouTube Safety Redirect>Statistics.Counter.Increment("BlockedByURLFilter",1)<Default>Redirect if text matches Off and there is a cookie.
      EnabledIf Safety Mode is Off and There is No Cookie Block
      1: Body.ToString(0,Body.Size) matches *Off*
      Block<YouTube Safety Mode Block>Statistics.Counter.Increment("BlockedByURLFilter",1)<Default>Block if text matches Off and there is no cookie
      EnabledSet Flag for Rest of Transaction if Safety Mode On
      1: Body.ToString(0,Body.Size) matches *On*
      ContinueSet User-Defined.YouTube-SafetyMode-On = trueIf safety mode is on we can allow all remaining cycles by setting the UDP
      Handle Unsuccessful Safety Mode Set
      [This ruleset detects the case where YouTube reports that Safety Mode was successfully set, but it really wasn't because cookies were blocked. ]
      Enabled
      Applies to Requests: True / Responses: False / Embedded Objects: True
      1: HTMLElement.HasAttribute("class") equals true
      2: AND HTMLElement.Attribute("class") matches yt-alert-content
      EnabledRuleActionEventsComments
      EnabledChange Safety Mode Successfully Set Message If Cookie Not Enabled
      1: Body.ToString(0,Body.Size) matches *Successfully*
      ContinueSet User-Defined.YouTube-SafetyMode-Notification = Body.ToString(0,Body.Size)
      Set User-Defined.YouTube-SafetyMode-Notification = String.ReplaceFirst(User-Defined.YouTube-SafetyMode-Notification,"Successfully enabled Safety Mode","Failed to enable Safety Mode - Cookies Blocked")
      Save Body of Object, and modify.
      EnabledChange Safety Mode Notification
      1: Body.ToString(0,Body.Size) matches *Successfully*
      RemoveBody.Insert(0,User-Defined.YouTube-SafetyMode-Notification)Remove original body and replace with modified.

       

      The simpler version (v2) looks like this:

       

      Rule Sets
      YouTube Enforce Safety Mode v2
      [Ruleset for enforcing YouTube Safety mode. Only applies to hostnames that match in the YouTube Hosts wildcard list. Note that cookies must be enabled for youtube.com, otherwise attempted access to any video will be blocked.]
      Enabled
      Applies to Requests: True / Responses: False / Embedded Objects: False
      1: URL.Host matches in list YouTube Hosts
      EnabledRuleActionEventsComments
      EnabledAllow URL Paths in Path List No Cookie
      1: URL.Path is in list Path List No Cookie
      2: AND Header.Request.Get("Cookie") does not match in list You Tube Safety Cookie
      Stop Rule SetOptional rule to allow base path when no cookie is set. Handles first user visit without blocking, if cookies are not enabled.
      EnabledAllow Set Safety Mode
      1: URL.Path equals "/set_safety_mode"
      2: AND URL.GetParameter("safety_mode") equals "true"
      Stop Rule SetAllow any requests that set safety mode to true
      EnabledBlock Disable Safety Mode for YouTube Hosts
      1: (URL.Path equals "/set_safety_mode"
      2: AND URL.GetParameter("safety_mode") does not equal "true")
      3: OR Header.Request.Exists("Cookie") equals false
      Block<YouTube Safety Mode Block>Block if no cookie or if attempt to disable safety mode
      EnabledEnforce Safety Mode for YouTube Hosts - Using Redirect
      1: Header.Request.Get("Cookie") does not match in list You Tube Safety Cookie
      Redirect<YouTube Safety Redirect>Any requests that don't have a cookie for safety mode are explicitly redirected. This is the preferred method to use for the redirect as it is more likely to be compatibile with most browsers. A URL rewrite using a Set URL event would also work but results in the browser receiving a redirect to the same URL that was originally requested and some browsers won't accept that.

       

      Message was edited by: jebeling on 6/28/11 5:55:09 PM CDT
        1 2 Previous Next