←Select platform

DomainWhitelist Property

Summary

Optional domain whitelist to be used when loading HTML files.

Syntax
C#
C++/CLI
Python
public string DomainWhitelist { get; set; } 
public:  
   property String^ DomainWhitelist 
   { 
      String^ get() 
      void set(String^ value) 
   } 
DomainWhitelist # get and set (CodecsHtmlLoadOptions) 

Property Value

Optional domain whitelist to be used when loading HTML files. The default value is null.

Remarks

DomainWhitelist can be used to allow loading resources from only certain domains when loading HTML files. The engine will loop through each resource in the input HTML and clears it if it does not belong to the specified domains.

By default, the value of DomainWhitelist is null and all domains are allowed. To allow domains only from certain domains, add them to this property as a string separated by the pipe (|) character.

The engine will remove the domains of the <img> elements by selecting and clearing the src attribute. Therefore, domains not in the whitelist are not reached.

The domains can also contain the wildcard ('*') character, which can represent anything of zero or more characters. So *domain.com will accept images from domain.com, www.domain.com, images-domain.com, images.domain.com, etc. In other words using domain.com will show images from any domain name that ends in "domain.com". The wildcard can also be in the middle of the string, so domain.com will accept domain.com, domain1.com, domain2.com, domainxx.com, etc.

For instance, assume the following HTML file:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
</head> 
<body> 
   <p>Image1</p> 
   			<div class="tutorial-image"><img src="https://www.domain1.com/images/image1.jpg"  title="DomainWhitelist Property"/></div> 
   <p>Image2</p> 
   			<div class="tutorial-image"><img src="https://www.domain2.com/images/image2.jpg"  title="DomainWhitelist Property"/></div> 
   <p>Image3</p> 
   			<div class="tutorial-image"><img src="https://www.domain3.com/images/image3.jpg"  title="DomainWhitelist Property"/></div> 
</body> 
</html> 

When loading this file as raster or SVG image, the HTML engine will downloads all images and renders them into the output.

To enable resources only from domain1, set the value of DomainWhitelist as follows:

C#
rasterCodecsInstance.Options.Html.Load.DomainWhitelist = "domain1.com"; 

Re-load the file and notice how only image1 is loaded and rendered.

To enable resources only from domain1 and domain2, set the value of DomainWhitelist as follows:

C#
rasterCodecsInstance.Options.Html.Load.DomainWhitelist = "domain1.com|domain2.com"; 

Re-load the file and notice how image1 and image2 are loaded and rendered.

To enable resources from domain.com, set the value of DomainWhitelist as follows:

C#
rasterCodecsInstance.Options.Html.Load.DomainWhitelist = "domain*.com"; 

Re-load the file and notice how image1, image2 and image3 are loaded and rendered.

To disable all resources from external domains, set DomainWhitelist to a value that will always fail the test, for example:

C#
rasterCodecsInstance.Options.Html.Load.DomainWhitelist = "does-not-exist-domain"; 
Re-load the file and notice that no images are loaded and rendered.
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
 
public void CodecsHtmlOptions_Example() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      // Use the default HTML rendering engine - CodecsHtmlOptions & CodecsHtmlLoadOptions reference 
      codecs.Options.Html.Load.HtmlEngine = CodecsHtmlEngine.Auto; 
      // Set the HTML options to only allow loading resources from the leadtools.com domain: 
      codecs.Options.Html.Load.DomainWhitelist = "leadtools.com"; 
      // Disable all JavaScript embedded in the HTML file 
      codecs.Options.Html.Load.EnableJS = false; 
      // Load the image 
      using (RasterImage image = codecs.Load("file.html", 1)) 
      { 
         // Do something with image 
      } 
   } 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.