Commit e77b5b74 authored by Tim Rühsen's avatar Tim Rühsen Committed by Daniel Stenberg
Browse files

cookies: Add support for Mozilla's Publix Suffix List

Use libpsl to check the domain value of Set-Cookie headers (and cookie
jar entries) for not being a Publix Suffix.

The configure script checks for "libpsl" by default. Disable the check
with --without-libpsl.

Ref: https://publicsuffix.org/
Ref: https://github.com/publicsuffix/list
Ref: https://github.com/rockdaboot/libpsl
parent 684816cd
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ curl_verbose_msg="enabled (--disable-verbose)"
   curl_rtsp_msg="no      (--enable-rtsp)"
   curl_rtmp_msg="no      (--with-librtmp)"
  curl_mtlnk_msg="no      (--with-libmetalink)"
    curl_psl_msg="no      (--with-libpsl)"

    init_ssl_msg=${curl_ssl_msg}

@@ -2314,6 +2315,27 @@ dnl **********************************************************************

CURL_CHECK_CA_BUNDLE

dnl **********************************************************************
dnl Check for libpsl
dnl **********************************************************************

AC_ARG_WITH(libpsl,
           AS_HELP_STRING([--without-libpsl],
           [disable support for libpsl cookie checking]),
           with_libpsl=$withval,
           with_libpsl=yes)
if test $with_libpsl != "no"; then
  AC_SEARCH_LIBS(psl_builtin, psl,
    [curl_psl_msg="yes";
     AC_DEFINE([USE_LIBPSL], [1], [PSL support enabled])
     ],
    [curl_psl_msg="no      (libpsl not found)";
     AC_MSG_WARN([libpsl was not found])
     ]
  )
fi
AM_CONDITIONAL([USE_LIBPSL], [test "$curl_psl_msg" = "yes"])

dnl **********************************************************************
dnl Check for libmetalink
dnl **********************************************************************
@@ -3742,6 +3764,7 @@ AC_MSG_NOTICE([Configured to build curl/libcurl:
  RTSP support:     ${curl_rtsp_msg}
  RTMP support:     ${curl_rtmp_msg}
  metalink support: ${curl_mtlnk_msg}
  PSL support:      ${curl_psl_msg}
  HTTP2 support:    ${curl_h2_msg}
  Protocols:        ${SUPPORT_PROTOCOLS}
])
+21 −0
Original line number Diff line number Diff line
@@ -84,6 +84,10 @@ Example set of cookies:

#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)

#ifdef USE_LIBPSL
# include <libpsl.h>
#endif

#include "curl_printf.h"
#include "urldata.h"
#include "cookie.h"
@@ -379,6 +383,10 @@ Curl_cookie_add(struct SessionHandle *data,
  bool replace_old = FALSE;
  bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */

#ifdef USE_LIBPSL
  const psl_ctx_t *psl;
#endif

#ifdef CURL_DISABLE_VERBOSE_STRINGS
  (void)data;
#endif
@@ -777,6 +785,19 @@ Curl_cookie_add(struct SessionHandle *data,
  /* at first, remove expired cookies */
  remove_expired(c);

#ifdef USE_LIBPSL
  /* Check if the domain is a Public Suffix and if yes, ignore the cookie.
     This needs a libpsl compiled with builtin data. */
  if(co->domain && !isip(co->domain) && (psl = psl_builtin()) != NULL) {
    if(psl_is_public_suffix(psl, co->domain)) {
      infof(data, "cookie '%s' dropped, domain '%s' is a public suffix\n",
            co->name, co->domain);
      freecookie(co);
      return NULL;
    }
  }
#endif

  clist = c->cookies;
  replace_old = FALSE;
  while(clist) {
+9 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@
#include <stringprep.h>
#endif

#ifdef USE_LIBPSL
#include <libpsl.h>
#endif

#if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
#include <iconv.h>
#endif
@@ -100,6 +104,11 @@ char *curl_version(void)
    ptr += len;
  }
#endif
#ifdef USE_LIBPSL
  len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
  left -= len;
  ptr += len;
#endif
#ifdef USE_WIN32_IDN
  len = snprintf(ptr, left, " WinIDN");
  left -= len;
+3 −0
Original line number Diff line number Diff line
@@ -316,6 +316,9 @@ void tool_version_info(void)
    }
#ifdef USE_METALINK
    printf("Metalink ");
#endif
#ifdef USE_LIBPSL
    printf("PSL ");
#endif
    puts(""); /* newline */
  }
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ test1104 test1105 test1106 test1107 test1108 test1109 test1110 test1111 \
test1112 test1113 test1114 test1115 test1116 test1117 test1118 test1119 \
test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 \
test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \
test1136 \
\
test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
test1208 test1209 test1210 test1211 test1212 test1213 test1214 test1215 \
Loading