Ejemplo n.º 1
0
        public bool isWhitelistedURL(string host, string pathAndQuery, out string reason)
        {
            bool         allowed    = false;
            DomainPolicy domainRule = findAllowedDomain(host ?? "");

            if (domainRule != null)
            {
                allowed = isWhitelistedEP(domainRule, pathAndQuery ?? "", out reason);

                if (allowed) // Finally check for banned phrases.
                {
                    string phrase_reason = "";
                    allowed = isContentAllowed(host + pathAndQuery, BlockPhraseScope.URL, out phrase_reason);
                    if (!allowed)
                    {
                        reason = host + pathAndQuery + ", " + phrase_reason;
                    }
                }
            }
            else
            {
                reason = "Domain <*" + host + "*> is not whitelisted";
            }

            return(allowed);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check if ep is in policy
        /// </summary>
        /// <returns>true if allowed</returns>
        public bool isWhitelistedEP(DomainPolicy domainObj, string ep, out string reason)
        {
            if (domainObj == null)
            {
                reason = "domain object is null";
                return(false);
            }

            if (domainObj.DomainBlocked)
            {
                reason = "Domain <*" + domainObj.DomainFormat + "*> in block mode";
                return(false);
            }

            bool allowed = false;

            reason = "block <*" + ep + "*> because not in <*" + domainObj.DomainFormat + "*> (not whitelisted) ";


            // check if ep in domain
            if (domainObj.AllowEP.Count > 0)
            {
                // Whitelist : All EP are blocked unless some ep allow (and no block ep later).
                for (int i = 0; i < domainObj.AllowEP.Count; i++)
                {
                    if (checkEPRuleMatch(domainObj.AllowEP[i], ep))
                    {
                        allowed = true;
                        reason  = domainObj.DomainFormat + ep + " is allowed by " + domainObj.AllowEP[i].ToString();
                        break;
                    }
                }
            }
            else
            {
                // All EP allowed unless found by block ep
                allowed = true;
            }

            if (allowed)
            {
                for (int i = 0; i < domainObj.BlockEP.Count; i++)
                {
                    if (checkEPRuleMatch(domainObj.BlockEP[i], ep))
                    {
                        allowed = false;
                        reason  = "<*" + domainObj.DomainFormat + ep + "*> is blocked by <*" + domainObj.BlockEP[i].ToString() + "*>";
                        break;
                    }
                }
            }


            return(allowed);
        }
Ejemplo n.º 3
0
        public bool isTrustedHost(string host)
        {
            DomainPolicy domain = allowedDomainsTrie.CheckDomain(host)?.Tag;

            return(domain != null && domain.Trusted);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check if Host (domain) is in policy
        /// </summary>
        /// <returns>true if allowed</returns>
        public bool isWhitelistedHost(string host)
        {
            DomainPolicy domain = allowedDomainsTrie.CheckDomain(host)?.Tag;

            return(domain != null);
        }