Exemplo n.º 1
0
        protected void ProcessHtmlUrlTag(HtmlTagContextAttribute filterAttribute, HtmlWriter writer)
        {
            string         value          = filterAttribute.Value;
            AttachmentLink attachmentLink = this.IsInlineReference(value);

            if (attachmentLink != null)
            {
                this.OutputInlineReference(filterAttribute, attachmentLink, writer);
                return;
            }
            SafeHtmlCallback.TypeOfUrl typeOfUrl = SafeHtmlCallback.GetTypeOfUrl(filterAttribute.Value, filterAttribute.Id);
            if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Redirection)
            {
                filterAttribute.Write();
                this.hasFoundRedirUrlInCurrentPass = true;
                return;
            }
            if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Trusted || typeOfUrl == SafeHtmlCallback.TypeOfUrl.Local)
            {
                filterAttribute.Write();
                return;
            }
            if (typeOfUrl == SafeHtmlCallback.TypeOfUrl.Unknown)
            {
                writer.WriteAttribute(filterAttribute.Id, "  ");
            }
        }
Exemplo n.º 2
0
        protected void ProcessImageTag(HtmlTagContextAttribute filterAttribute, HtmlTagContext context, HtmlWriter writer)
        {
            AirSyncDiagnostics.Assert(context != null);
            string         value          = filterAttribute.Value;
            AttachmentLink attachmentLink = this.IsInlineReference(value);

            if (attachmentLink != null)
            {
                this.OutputInlineReference(filterAttribute, attachmentLink, writer);
                return;
            }
            if (SafeHtmlCallback.IsSafeUrl(filterAttribute.Value, filterAttribute.Id))
            {
                filterAttribute.Write();
            }
        }
Exemplo n.º 3
0
        // Token: 0x06001397 RID: 5015 RVA: 0x00070BF8 File Offset: 0x0006EDF8
        public static Stream ConvertHtmlStream(Item item, long truncationSizeByChars, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            SafeHtmlCallback      safeHtmlCallback = new SafeHtmlCallback(item);
            bool                  flag             = truncationSizeByChars == -1L;
            BodyReadConfiguration bodyReadConfiguration;

            if (flag)
            {
                bodyReadConfiguration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, "utf-8");
                bodyReadConfiguration.SetHtmlOptions(HtmlStreamingFlags.FilterHtml, safeHtmlCallback);
            }
            else
            {
                bodyReadConfiguration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, "utf-8");
                bodyReadConfiguration.SetHtmlOptions(HtmlStreamingFlags.FilterHtml, safeHtmlCallback, new int?(1024));
            }
            AirSyncStream airSyncStream = new AirSyncStream();
            Body          body          = null;

            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            else
            {
                body = item.Body;
            }
            uint streamHash;

            using (Stream stream = body.OpenReadStream(bodyReadConfiguration))
            {
                StreamHelper.CopyStream(stream, airSyncStream, Encoding.UTF8, (int)truncationSizeByChars, true, out streamHash);
            }
            airSyncStream.StreamHash = (int)streamHash;
            totalDataSize            = ((truncationSizeByChars < 0L || airSyncStream.Length < truncationSizeByChars) ? airSyncStream.Length : body.Size);
            attachmentLinks          = safeHtmlCallback.AttachmentLinks;
            return(airSyncStream);
        }
Exemplo n.º 4
0
 protected static void ProcessMicrodataTag(bool writeTag, HtmlTagContext context, List <HtmlAttributeId> safeAttributes)
 {
     if (!writeTag)
     {
         context.DeleteTag();
         return;
     }
     foreach (HtmlTagContextAttribute htmlTagContextAttribute in context.Attributes)
     {
         if (safeAttributes.Contains(htmlTagContextAttribute.Id))
         {
             bool flag = true;
             if (htmlTagContextAttribute.Id == HtmlAttributeId.Href && !SafeHtmlCallback.IsSafeUrl(htmlTagContextAttribute.Value, htmlTagContextAttribute.Id))
             {
                 flag = false;
             }
             if (flag)
             {
                 htmlTagContextAttribute.Write();
             }
         }
     }
 }
Exemplo n.º 5
0
        public override void ProcessTag(HtmlTagContext context, HtmlWriter writer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            string text  = null;
            string text2 = null;
            string text3 = null;

            if (context.TagId == HtmlTagId.Link)
            {
                bool writeTag = SafeHtmlCallback.WriteTagWithMicroData(context);
                SafeHtmlCallback.ProcessMicrodataTag(writeTag, context, SafeHtmlCallback.linkTagAttributes);
                return;
            }
            if (context.TagId == HtmlTagId.Head)
            {
                context.WriteTag(true);
                return;
            }
            if (context.TagId == HtmlTagId.Meta)
            {
                bool writeTag2 = SafeHtmlCallback.WriteTagWithMicroData(context);
                SafeHtmlCallback.ProcessMicrodataTag(writeTag2, context, SafeHtmlCallback.metaTagAttributes);
                return;
            }
            if (context.TagId == HtmlTagId.Base)
            {
                foreach (HtmlTagContextAttribute attribute in context.Attributes)
                {
                    if (SafeHtmlCallback.IsBaseTag(context.TagId, attribute))
                    {
                        string value = attribute.Value;
                        if (!Uri.TryCreate(value, UriKind.Absolute, out this.baseRef))
                        {
                            this.baseRef = null;
                            break;
                        }
                        break;
                    }
                }
            }
            context.WriteTag();
            bool flag5 = false;

            foreach (HtmlTagContextAttribute htmlTagContextAttribute in context.Attributes)
            {
                if (context.TagId == HtmlTagId.Form || context.TagId == HtmlTagId.Input)
                {
                    if (htmlTagContextAttribute.Id != HtmlAttributeId.Src && htmlTagContextAttribute.Id != HtmlAttributeId.Action && htmlTagContextAttribute.Id != HtmlAttributeId.Method && htmlTagContextAttribute.Id != HtmlAttributeId.Target)
                    {
                        htmlTagContextAttribute.Write();
                    }
                }
                else if (htmlTagContextAttribute.Id != HtmlAttributeId.UseMap)
                {
                    if (SafeHtmlCallback.IsUrlTag(context.TagId, htmlTagContextAttribute))
                    {
                        if (!flag)
                        {
                            this.ProcessHtmlUrlTag(htmlTagContextAttribute, writer);
                            flag = true;
                        }
                    }
                    else if (SafeHtmlCallback.IsImageTag(context.TagId, htmlTagContextAttribute))
                    {
                        if ((htmlTagContextAttribute.Id == HtmlAttributeId.Src && !flag2) || (htmlTagContextAttribute.Id == HtmlAttributeId.DynSrc && !flag3) || (htmlTagContextAttribute.Id == HtmlAttributeId.LowSrc && !flag4))
                        {
                            this.ProcessImageTag(htmlTagContextAttribute, context, writer);
                            if (htmlTagContextAttribute.Value == "rtfimage://")
                            {
                                flag5 = true;
                            }
                            if (htmlTagContextAttribute.Id == HtmlAttributeId.Src)
                            {
                                flag2 = true;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.DynSrc)
                            {
                                flag3 = true;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.LowSrc)
                            {
                                flag4 = true;
                            }
                        }
                    }
                    else if (SafeHtmlCallback.IsBackgroundAttribute(htmlTagContextAttribute))
                    {
                        this.ProcessImageTag(htmlTagContextAttribute, context, writer);
                    }
                    else if (!SafeHtmlCallback.IsTargetTagInAnchor(context.TagId, htmlTagContextAttribute))
                    {
                        if (SafeHtmlCallback.IsSanitizingAttribute(htmlTagContextAttribute))
                        {
                            if (htmlTagContextAttribute.Id == HtmlAttributeId.Border)
                            {
                                text = htmlTagContextAttribute.Value;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.Height)
                            {
                                text2 = htmlTagContextAttribute.Value;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.Width)
                            {
                                text3 = htmlTagContextAttribute.Value;
                            }
                        }
                        else
                        {
                            htmlTagContextAttribute.Write();
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3) && this.hasBlockedImagesInCurrentPass)
            {
                SafeHtmlCallback.SanitizeImage(writer, text, text2, text3);
            }
            else if (!this.hasBlockedImagesInCurrentPass)
            {
                if (flag5)
                {
                    writer.WriteAttribute(HtmlAttributeId.Height, "0");
                    writer.WriteAttribute(HtmlAttributeId.Width, "0");
                }
                else
                {
                    if (!string.IsNullOrEmpty(text2))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Height, text2);
                    }
                    if (!string.IsNullOrEmpty(text3))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Width, text3);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Border, text);
                    }
                }
            }
            if (this.hasFoundRedirUrlInCurrentPass)
            {
                writer.WriteAttribute(HtmlAttributeId.Target, "_BLANK");
            }
            this.hasBlockedImagesInCurrentPass = false;
            this.hasFoundRedirUrlInCurrentPass = false;
        }
Exemplo n.º 6
0
 protected static bool IsSafeUrl(string urlString, HtmlAttributeId htmlAttr)
 {
     SafeHtmlCallback.TypeOfUrl typeOfUrl = SafeHtmlCallback.GetTypeOfUrl(urlString, htmlAttr);
     return(typeOfUrl != SafeHtmlCallback.TypeOfUrl.Unknown);
 }
Exemplo n.º 7
0
        // Token: 0x0600139C RID: 5020 RVA: 0x00070E68 File Offset: 0x0006F068
        private static KeyValuePair <HtmlStreamingFlags, HtmlCallbackBase> GetSafeHtmlCallbacks(Item item)
        {
            SafeHtmlCallback value = new SafeHtmlCallback(item);

            return(new KeyValuePair <HtmlStreamingFlags, HtmlCallbackBase>(HtmlStreamingFlags.FilterHtml, value));
        }