1

I am using checkmarx for security vulnerabilities in code. (react-native). I enabled deep linking in react-native using this guide from the official documentation for ios https://reactnative.dev/docs/linking. From the documentation i added this code to AppDelegate.m


- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

However checkmarx reports that i need to sanitize or validate the url to prevent XSS attacks, any idea on how to achieve this?

Josh
  • 827
  • 5
  • 7

1 Answers1

0

To mitigate the XSS vulnerability in the code, you must URL encode the url argument by using the stringByAddingPercentEncodingWithAllowedCharacters method:

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{

NSString *urlEncoded = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];

  return [RCTLinkingManager application:application openURL:urlEncoded options:options];
} 
securecodeninja
  • 2,497
  • 3
  • 16
  • 22