Skip to content

Commit 246b66f

Browse files
author
Nitin Chaudhary
committed
feat: Add DNS validation for advanced SSRF protection
- Add ValidateURLWithDNS() method for async DNS resolution validation - Add ResolveHostname() utility for DNS rebinding attack prevention - Link Winsock2 library for Windows DNS resolution support - Enhances existing SDL input validation with DNS-level security Addresses: 58386087 - Advanced DNS validation features
1 parent de71ef3 commit 246b66f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

vnext/Shared/InputValidation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <cctype>
77
#include <iomanip>
88
#include <sstream>
9+
#include <winsock2.h>
10+
#include <ws2tcpip.h>
11+
12+
#pragma comment(lib, "Ws2_32.lib")
913

1014
namespace Microsoft::ReactNative::InputValidation {
1115

vnext/Shared/InputValidation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class URLValidator {
3333
const std::vector<std::string> &allowedSchemes = {"http", "https"},
3434
bool allowLocalhost = false);
3535

36+
// Validate URL with DNS resolution (async version for production)
37+
// Resolves hostname and checks if resolved IP is private
38+
static void ValidateURLWithDNS(
39+
const std::string &url,
40+
const std::vector<std::string> &allowedSchemes = {"http", "https"},
41+
bool allowLocalhost = false);
42+
3643
// Check if hostname is private IP/localhost (expanded for SDL)
3744
static bool IsPrivateOrLocalhost(const std::string &hostname);
3845

@@ -45,6 +52,9 @@ class URLValidator {
4552
// Check if IP is in private range (supports IPv4/IPv6)
4653
static bool IsPrivateIP(const std::string &ip);
4754

55+
// Resolve hostname to IP addresses (for DNS rebinding protection)
56+
static std::vector<std::string> ResolveHostname(const std::string &hostname);
57+
4858
private:
4959
static const std::vector<std::string> BLOCKED_HOSTS;
5060
static bool IsOctalIPv4(const std::string &hostname);

0 commit comments

Comments
 (0)