Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate VPN errors before re-throwing them #1054

Merged
merged 8 commits into from
Nov 3, 2024

Conversation

samsymons
Copy link
Contributor

@samsymons samsymons commented Nov 1, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/414709148257752/1208225499545869/f
iOS PR: duckduckgo/iOS#3513
macOS PR: duckduckgo/macos-browser#3490
What kind of version bump will this require?: Major

Description:

This PR attempts to catch malformed errors before they get thrown to the OS. It also informs us when this happens.

Steps to test this PR:

To test this, we need to make sure that existing errors still throw as expected, and that errors we're trying to filter out get successfully caught.

For testing existing errors on iOS:

  1. Open PacketTunnelProvider.swift
  2. Go to func startTunnel(options: [String: NSObject]? = nil) async throws, which is the function where errors from the rest of the VPN get thrown to the OS
  3. Pick one of the try functions in startTunnel, for example try await startTunnel(onDemand: startupOptions.startupMethod == .automaticOnDemand)
  4. Inside that function, throw an error such as TunnelError.simulateTunnelFailureError
  5. Now, attempt to start the VPN, and check that it fails
  6. After it has failed, go to the iOS debug menu's Network Protection section, and check the metadata at the very bottom to confirm that the lastDisconnectError value to make sure it matches the error you used in step 4

For testing errors that we're filtering out:

First, add the following error somewhere in PacketTunnelProvider:

    enum ErrorThatCrashes: CustomNSError {
        case crash

        var errorCode: Int {
            return 123
        }

        static var errorDomain: String {
            return "error-domain"
        }

        var errorUserInfo: [String: Any] {
            return [
                NSUnderlyingErrorKey: "testing"
            ]
        }
    }

This error uses an underlying error that isn't a valid error object, which causes a VPN extension crash. Next:

  1. Throw an instance of that error from the same place that you used in the first set of instructions
  2. Check the Debug menu's Network Protection section and confirm that you see a valid error object in the metadata which is of the type InvalidDiagnosticError
  3. Also, check that it contains an underlying error that is just domain and code

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

Comment on lines +1846 to +1847
let newError = NSError(domain: (error as NSError).domain, code: (error as NSError).code)
return [NSUnderlyingErrorKey: newError]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to know what error violated the underlying error validation, but without actually including its underlying errors - knowing its domain and code should be enough to debug further.

Copy link
Contributor

@diegoreymendez diegoreymendez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.

Sources/NetworkProtection/PacketTunnelProvider.swift Outdated Show resolved Hide resolved
Sources/NetworkProtection/PacketTunnelProvider.swift Outdated Show resolved Hide resolved
…the-os

* main:
  Bump github.com/duckduckgo/privacy-dashboard from 5.3.0 to 7.1.1 (#1046)
  Bump github.com/duckduckgo/sync_crypto from 0.2.0 to 0.3.0 (#1048)
  Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0 (#1050)
  Update to subscription cookie (#1053)
  Bug Fix: Phishing Detection Dataset Discrepancies (#1032)
  Include www.youtube.com as Youtube host (#1028)
…the-os

* main:
  Revert "Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0" (#1055)
@samsymons samsymons merged commit 45261df into main Nov 3, 2024
7 checks passed
@samsymons samsymons deleted the sam/validate-errors-before-throwing-them-to-the-os branch November 3, 2024 22:57
samsymons added a commit that referenced this pull request Nov 3, 2024
* main:
  Validate VPN errors before re-throwing them (#1054)
  Allowing users to delete suggestions (#1027)
  Revert "Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0" (#1055)
  Bump github.com/duckduckgo/privacy-dashboard from 5.3.0 to 7.1.1 (#1046)
  Bump github.com/duckduckgo/sync_crypto from 0.2.0 to 0.3.0 (#1048)
  Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0 (#1050)
samsymons added a commit that referenced this pull request Nov 4, 2024
* main:
  Validate VPN errors before re-throwing them (#1054)
  Allowing users to delete suggestions (#1027)
  Revert "Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0" (#1055)
  Bump github.com/duckduckgo/privacy-dashboard from 5.3.0 to 7.1.1 (#1046)
  Bump github.com/duckduckgo/sync_crypto from 0.2.0 to 0.3.0 (#1048)
  Bump github.com/1024jp/gzipswift from 6.0.1 to 6.1.0 (#1050)
  Update to subscription cookie (#1053)
  Bug Fix: Phishing Detection Dataset Discrepancies (#1032)
  Include www.youtube.com as Youtube host (#1028)
  Ignore GRDB (#1052)
  Connect refactored update flow to the new release notes page (#1025)
  Add to Dock - Add extra custom view to Contextual Dialog Content (#1043)
  Dependabot for BSK (#1045)
  Update autofill to 15.1.0 (#1044)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants