Skip to content

Commit

Permalink
Feature: Option to allow untrusted HTTPS certificates for screenshots…
Browse files Browse the repository at this point in the history
… & link checking (#204)
  • Loading branch information
axllent committed Nov 11, 2023
1 parent 7423625 commit 4c5b024
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func init() {
rootCmd.Flags().StringVar(&config.WebhookURL, "webhook-url", config.WebhookURL, "Send a webhook request for new messages")
rootCmd.Flags().IntVar(&webhook.RateLimit, "webhook-limit", webhook.RateLimit, "Limit webhook requests per second")

rootCmd.Flags().BoolVar(&config.AllowUntrustedTLS, "allow-untrusted-tls", config.AllowUntrustedTLS, "Do not verify HTTPS certificates (link checker & screenshots)")

rootCmd.Flags().StringVarP(&config.SMTPCLITags, "tag", "t", config.SMTPCLITags, "Tag new messages matching filters")
rootCmd.Flags().BoolVarP(&logger.QuietLogging, "quiet", "q", logger.QuietLogging, "Quiet logging (errors only)")
rootCmd.Flags().BoolVarP(&logger.VerboseLogging, "verbose", "v", logger.VerboseLogging, "Verbose logging")
Expand Down Expand Up @@ -199,6 +201,9 @@ func initConfigFromEnv() {
if getEnabledFromEnv("MP_BLOCK_REMOTE_CSS_AND_FONTS") {
config.BlockRemoteCSSAndFonts = true
}
if getEnabledFromEnv("MP_ALLOW_UNTRUSTED_TLS") {
config.AllowUntrustedTLS = true
}
if getEnabledFromEnv("MP_QUIET") {
logger.QuietLogging = true
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ var (
// ContentSecurityPolicy for HTTP server - set via VerifyConfig()
ContentSecurityPolicy string

// AllowUntrustedTLS allows untrusted HTTPS connections link checking & screenshot generation
AllowUntrustedTLS bool

// Version is the default application version, updated on release
Version = "dev"

Expand Down
10 changes: 9 additions & 1 deletion internal/linkcheck/status.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package linkcheck

import (
"crypto/tls"
"net/http"
"regexp"
"sync"
Expand Down Expand Up @@ -59,8 +60,15 @@ func doHead(link string, followRedirects bool) (int, error) {

timeout := time.Duration(10 * time.Second)

tr := &http.Transport{}

if config.AllowUntrustedTLS {
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}

client := http.Client{
Timeout: timeout,
Timeout: timeout,
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if followRedirects {
return nil
Expand Down
10 changes: 9 additions & 1 deletion server/handlers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package handlers

import (
"crypto/tls"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -31,8 +32,15 @@ func ProxyHandler(w http.ResponseWriter, r *http.Request) {
return
}

tr := &http.Transport{}

if config.AllowUntrustedTLS {
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}

client := &http.Client{
Timeout: 10 * time.Second,
Transport: tr,
Timeout: 10 * time.Second,
}

req, err := http.NewRequest("GET", uri, nil)
Expand Down

0 comments on commit 4c5b024

Please sign in to comment.