feat(chromium): add --chromium-disable-web-security property

This commit is contained in:
Julien Neuhart
2021-11-21 13:30:24 +01:00
parent 7022ebe4ca
commit 704dfc25e6
3 changed files with 12 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ API_DISABLE_HEALTH_CHECK_LOGGING=false
CHROMIUM_USER_AGENT=
CHROMIUM_INCOGNITO=false
CHROMIUM_IGNORE_CERTIFICATE_ERRORS=false
CHROMIUM_DISABLE_WEB_SECURITY=false
CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES=false
CHROMIUM_PROXY_SERVER=
CHROMIUM_ALLOW_LIST=
@@ -79,6 +80,7 @@ run: ## Start a Gotenberg container
--chromium-user-agent=$(CHROMIUM_USER_AGENT) \
--chromium-incognito=$(CHROMIUM_INCOGNITO) \
--chromium-ignore-certificate-errors=$(CHROMIUM_IGNORE_CERTIFICATE_ERRORS) \
--chromium-disable-web-security=$(CHROMIUM_DISABLE_WEB_SECURITY) \
--chromium-allow-file-access-from-files=$(CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES) \
--chromium-proxy-server=$(CHROMIUM_PROXY_SERVER) \
--chromium-allow-list=$(CHROMIUM_ALLOW_LIST) \

View File

@@ -51,6 +51,7 @@ type Chromium struct {
userAgent string
incognito bool
ignoreCertificateErrors bool
disableWebSecurity bool
allowFileAccessFromFiles bool
proxyServer string
allowList *regexp.Regexp
@@ -186,6 +187,7 @@ func (mod Chromium) Descriptor() gotenberg.ModuleDescriptor {
fs.String("chromium-user-agent", "", "Override the default User-Agent header")
fs.Bool("chromium-incognito", false, "Start Chromium with incognito mode")
fs.Bool("chromium-ignore-certificate-errors", false, "Ignore the certificate errors")
fs.Bool("chromium-disable-web-security", false, "Don't enforce the same-origin policy")
fs.Bool("chromium-allow-file-access-from-files", false, "Allow file:// URIs to read other file:// URIs")
fs.String("chromium-proxy-server", "", "Set the outbound proxy server; this switch only affects HTTP and HTTPS requests")
fs.String("chromium-allow-list", "", "Set the allowed URLs for Chromium using a regular expression")
@@ -203,6 +205,7 @@ func (mod *Chromium) Provision(ctx *gotenberg.Context) error {
flags := ctx.ParsedFlags()
mod.userAgent = flags.MustString("chromium-user-agent")
mod.ignoreCertificateErrors = flags.MustBool("chromium-ignore-certificate-errors")
mod.disableWebSecurity = flags.MustBool("chromium-disable-web-security")
mod.allowFileAccessFromFiles = flags.MustBool("chromium-allow-file-access-from-files")
mod.proxyServer = flags.MustString("chromium-proxy-server")
mod.allowList = flags.MustRegexp("chromium-allow-list")
@@ -311,6 +314,10 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath
args = append(args, chromedp.IgnoreCertErrors)
}
if mod.disableWebSecurity {
args = append(args, chromedp.Flag("disable-web-security", true))
}
if mod.allowFileAccessFromFiles {
// See https://github.com/gotenberg/gotenberg/issues/356.
args = append(args, chromedp.Flag("allow-file-access-from-files", true))

View File

@@ -233,6 +233,7 @@ func TestChromium_PDF(t *testing.T) {
userAgent string
incognito bool
ignoreCertificateErrors bool
disableWebSecurity bool
allowFileAccessFromFiles bool
proxyServer string
allowList *regexp.Regexp
@@ -297,6 +298,7 @@ func TestChromium_PDF(t *testing.T) {
userAgent: "foo",
incognito: true,
ignoreCertificateErrors: true,
disableWebSecurity: true,
allowFileAccessFromFiles: true,
proxyServer: "foo",
},
@@ -349,6 +351,7 @@ func TestChromium_PDF(t *testing.T) {
mod.userAgent = tc.userAgent
mod.incognito = tc.incognito
mod.ignoreCertificateErrors = tc.ignoreCertificateErrors
mod.disableWebSecurity = tc.disableWebSecurity
mod.allowFileAccessFromFiles = tc.allowFileAccessFromFiles
mod.proxyServer = tc.proxyServer