Check a URL for High-Risk or Vulnerable Paths in Swift

Cloudmersive
1 min readMay 5, 2021

Server administration paths can be used in web applications or databases to specify the set of directories that are accessed. While these are very common and easy-to-use, they can provide a window for attackers to exploit and access directories that should be off-limits. Testing your URLs or paths for this vulnerability can be a tedious process, so in this brief tutorial we will demonstrate how you can use an API in Swift to automatically check your paths for this risk.

To use the API, we will input the target URL/relative path and our API key and call the function with the following code:

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)let parameters = "\"<string>\""
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.cloudmersive.com/validate/domain/url/is-admin-path")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("YOUR-API-KEY-HERE", forHTTPHeaderField: "Apikey")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()

The result will be returned instantly with no extra hassle needed.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.