Unauthorized access to screen - Swift

Unauthorized access to screen - Swift

Need

Prevention of unauthorized access to client information on the GLIA application

Context

  • Usage of Swift for iOS and macOS app development
  • Usage of UIKit for building modern and responsive user interfaces

Description

Non compliant code

        import UIKit

class AdvisorViewController: UIViewController {

    @IBOutlet weak var clientInfoTextView: UITextView!
    
    var clientData: ClientData?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if let clientData = clientData {
            clientInfoTextView.text = clientData.info
        }
    }
    
    func setClientData(_ data: ClientData) {
        self.clientData = data
    }
}
        
        

In the above Swift code, an advisor has access to a ClientData object that contains sensitive client information. The AdvisorViewController class has a clientData property that is used to store the client's data. This data is then displayed in a text view ( clientInfoTextView) when the view loads.

When an advisor logs into the user window and follows the flow that the user goes through when opening an account, they can call the setClientData(_:) method to set the clientData property. This means that the advisor can obtain different client data without the client being aware of it.

This code is vulnerable because it allows unauthorized access to sensitive client information. The advisor should not have access to this information, but the current implementation of the AdvisorViewController class allows them to obtain it.

Steps

  • Implement proper authentication and authorization mechanisms to ensure that only authorized users can access the AdvisorViewController.
  • Restrict access to client information based on user roles and permissions.
  • Ensure that client data is securely stored and transmitted, using encryption and secure protocols.
  • Implement logging and monitoring mechanisms to detect and track any unauthorized access attempts.
  • Regularly update and patch the application to address any security vulnerabilities.

Compliant code

        import UIKit

class AdvisorViewController: UIViewController {

    @IBOutlet weak var clientInfoTextView: UITextView!
    
    var clientData: ClientData?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Check if the user is authorized to view client data
        if User.current.role == .advisor {
            showAlertWith(title: "Unauthorized Access", message: "You are not authorized to view client data.")
            return
        }

        if let clientData = clientData {
            clientInfoTextView.text = clientData.info
        }
    }
    
    func setClientData(_ data: ClientData) {
        self.clientData = data
    }
    
    func showAlertWith(title: String, message: String) {
        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alertController.addAction(defaultAction)
        present(alertController, animated: true, completion: nil)
    }
}
        
        

The updated code now includes a check to see if the current user is authorized to view client data. If the user's role is 'advisor', an alert is shown stating "You are not authorized to view client data." and the function returns immediately, preventing any client data from being displayed.

The showAlertWith(title:message:) function is used to display an alert to the user. This function creates a UIAlertController with the provided title and message, adds a default 'OK' action to it, and presents it to the user.

This solution ensures that only authorized users can access the AdvisorViewController and view client data, addressing the identified security vulnerability. However, it's important to note that this is just one part of a comprehensive security strategy. Other measures such as secure data storage and transmission, logging and monitoring of access attempts, and regular updates and patches should also be implemented to protect against other potential vulnerabilities.

References