Optional domain whitelist to be used when loading HTML files.
public string DomainWhitelist { get; set; }
public:
property String^ DomainWhitelist
{
String^ get()
void set(String^ value)
}
DomainWhitelist # get and set (CodecsHtmlLoadOptions)
Optional domain whitelist to be used when loading HTML files. The default value is null.
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:
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:
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 domainrasterCodecsInstance.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:
rasterCodecsInstance.Options.Html.Load.DomainWhitelist = "does-not-exist-domain";
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;
using Leadtools.Pdf;
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
}
}
}
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.MinMaxBitsCommand;
public void codecsHtmlOptionsExample() throws URISyntaxException {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Example.html");
String outputFileName = combine(LEAD_VARS_IMAGES_DIR, "Result.jpg");
RasterCodecs codecs = new RasterCodecs();
// Use the default HTML rendering engine - CodecsHtmlOptions &
// CodecsHtmlLoadOptions reference
codecs.getOptions().getHtml().getLoad().setHtmlEngine(CodecsHtmlEngine.AUTO);
// Set the HTML options to only allow loading resources from the leadtools.com
// domain:
codecs.getOptions().getHtml().getLoad().setDomainWhitelist("leadtools.com");
// Disable all JavaScript embedded in the HTML file
codecs.getOptions().getHtml().getLoad().setEnableJS(false);
// Load the image
RasterImage image = codecs.load(srcFileName, 1);
// Do something with image
codecs.save(image, outputFileName, RasterImageFormat.JPEG, 0);
assertTrue("File unsuccessfully saved to " + outputFileName, (new File(outputFileName)).exists());
System.out.printf("File successfully saved to %s%n", outputFileName);
image.dispose();;
codecs.dispose();
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document