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

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
var semaphore = DispatchSemaphore (value: 0)let parameters = "\"<string>\""
let postData = .utf8)
var request = URLRequest(url: URL(string: "")!,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))
print(String(data: data, encoding: .utf8)!)

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store