SwiftPublicSuffixList - Public Suffix List domain name checker in Swift

Overview

swift workflow codecov License: MIT Issues Releases

SwiftPublicSuffixList

This library is a Swift implementation of the necessary code to check a domain name against the Public Suffix List list and identify if the domains should be restricted.

Restricted domains should not be allowed to set cookies, directly host websites or send/receive emails.

As of January 2022, the list contained over 9k entries.

Performance Considerations

Due to the high number of entries in the Public Suffix list (>9k), you may want to pre-load on a background thread the PublicSuffixRulesRegistry.rules soon after launching the app. Initial loading of the list may require between 100ms to 900ms depending on the host device.

Regular Updates Recommended

  • The Public Suffix List is updated regularly, if your application is published regularly you may be fine by simply pulling the latest version of the SwiftPublicSuffixList library. However it is recommended to have your application retrieve the latest copy of the public suffix list on a somewhat regular basis.

LAST UPDATED: 2022-01-29 15:30:00 EST

Shell Command

You can run the Utilities/update-suffix.swift from the command line to download & process the text file containing the Public Suffix List and re-generate the PublicSuffixRulesRegistry.swift file.

# swift update-suffix.swift

From Swift at runtime:

TODO!

Classes & Usage

PublicSuffixList

.match(_ candidate: String, rules: [[String]]) -> Match?

import SwiftPublicSuffixList

Using the default built-in Public Suffix List rules

if let match = PublicSuffixList.match("yahoo.com") {
    // match.isRestricted == false
}

Using a single custom validation rule, requiring domains to end with .com but allow any domain within the .com TLD

if let match = PublicSuffixList.match("yahoo.com", rules: [["com"]]) {
    // match.isRestricted == false
    // match.prevailingRule == ["com"]
    // match.matchedRules == [["com"]]
}

Using a single custom validation rule, restriction domains that end with .com but allowing any subdomain

if let match = PublicSuffixList.match("yahoo.com", rules: [["*","com"]]) {
   // yahoo.com matches \*.com and so it is restricted
   // match.isRestricted == true
   // match.prevailingRule == ["*","com"]
   // match.matchedRules == [["*","com"]]
}

if let match = PublicSuffixList.match("www.yahoo.com", [["*","com"]]) {
   // While yahoo.co matches \*.com and is restricted, there are no
   // restrictions for subdomains such as www.yahoo.com
   // match.isRestricted == false
   // match.prevailingRule == ["*","com"]
   // match.matchedRules == [["*","com"]]
}

Defining an exception to a more generic rule

if let match = PublicSuffixList.match("yahoo.com", rules: [["*","com"],["!yahoo","com"]]) {
    // Even if yahoo.com matches *.com, since there is an exception
    // for this domain (defined using !) it will not be restricted
    // match.isRestricted == false
    // match.prevailingRule == ["!yahoo","com"]
    // match.matchedRules == [["*","com"],["!yahoo","com"]]
}

.isUnrestricted(_ candiate: String, rules: [[String]]) -> Bool

Convenience function that will attempt to retrieve a match then return the value of !match.isRestricted. Will return false if no match was found.

if PublicSuffixList.isUnrestricted("yahoo.com") {
    // true! yahoo.com is unrestricted by default
}
You might also like...
Ios-App-ication-Swift - A simple iOS application made in Xcode using Swift
Ios-App-ication-Swift - A simple iOS application made in Xcode using Swift

📱 iPhone Calculator A simple iOS application made in Xcode using Swift. This ap

Save-the-dot-project-swift - Save the dot project with swift
Save-the-dot-project-swift - Save the dot project with swift

Save the Dot Apple introduced UIViewPropertyAnimator for iOS 10. We can use this

The Swift Package Index is the place to find Swift packages!
The Swift Package Index is the place to find Swift packages!

The Swift Package Index helps you make better decisions about the dependencies you use in your apps. The Swift Package Index is a search engine for pa

A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

Elegant library to manage the interactions between view and model in Swift
Elegant library to manage the interactions between view and model in Swift

An assistant to manage the interactions between view and model ModelAssistant is a mediator between the view and model. This framework is tailored to

CRUD is an object-relational mapping (ORM) system for Swift 4+.

CRUD is an object-relational mapping (ORM) system for Swift 4+. CRUD takes Swift 4 Codable types and maps them to SQL database tables. CRUD can create tables based on Codable types and perform inserts and updates of objects in those tables. CRUD can also perform selects and joins of tables, all in a type-safe manner.

CoreXLSX is a Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

Solutions to LeetCode by Swift
Solutions to LeetCode by Swift

LeetCode by Swift LeetCode Online Judge is a website containing many algorithm questions. Most of them are real interview questions of Google, Faceboo

Super lightweight DB written in Swift.
Super lightweight DB written in Swift.

Use of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. Pencil makes us store these values more easily.

Releases(1.1.6)
Owner
Dave Poirier
Dave Poirier
A proof-of-concept WebURL domain renderer, using a port of Chromium's IDN spoof-checking logic to protect against confusable domains

WebURLSpoofChecking A proof-of-concept WebURL.Domain renderer which uses a port of Chromium's IDN spoof-checking logic (Overview, Implementation) to p

Karl 3 Aug 6, 2022
Analytics layer abstraction, abstract analytics reporters and collect domain-driven analytic events.

?? Tentacles Current State: Work in Progress Documentation & Tests(100% completed, but needs refactoring and structuring) started but not done yet, im

Patrick 3 Dec 2, 2022
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.

PersistentStorageSerializable PersistentStorageSerializable is a protocol for automatic serialization and deserialization of Swift class, struct or NS

Ivan Rublev 163 Jun 3, 2021
BucketServer - Small API with SQLite database that saves notes for an iOS appliction called Bucket list

BucketList Server-Side Small API with SQLite database that saves notes for an iO

null 0 Dec 30, 2021
A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift

A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift. It features a great API and a battle-tested core. Supporting both MongoDB in server and embedded environments.

null 646 Dec 10, 2022
SQLite.swift - A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Stephen Celis 8.7k Jan 3, 2023
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

?? Easy to use SQLite ORM library written with Swift

Yevgeniy Zakharov 25 Oct 6, 2022
ObjectBox Swift - persisting your Swift objects superfast and simple

ObjectBox Swift ObjectBox is a superfast, light-weight object persistence framework. This Swift API seamlessly persists objects on-device for iOS and

ObjectBox 380 Dec 19, 2022
Shows the issue with swift using an ObjC class which has a property from a swift package.

SwiftObjCSwiftTest Shows the issue with swift using an ObjC class which has a property from a swift package. The Swift class (created as @objc derived

Scott Little 0 Nov 8, 2021