@@ -106,8 +106,12 @@ void ImageLoader::Initialize(React::ReactContext const &reactContext) noexcept {
106106void ImageLoader::getSize (std::string uri, React::ReactPromise<std::vector<double >> &&result) noexcept {
107107 // VALIDATE URI - file:// abuse PROTECTION (P0 Critical - CVSS 7.8)
108108 try {
109- // Allow data: URIs and http/https only
110- if (uri.find (" data:" ) != 0 ) {
109+ if (uri.find (" data:" ) == 0 ) {
110+ // Validate data URI size to prevent DoS through memory exhaustion
111+ ::Microsoft::ReactNative::InputValidation::SizeValidator::ValidateSize (
112+ uri.length(), ::Microsoft::ReactNative::InputValidation::SizeValidator::MAX_DATA_URI_SIZE, "Data URI");
113+ } else {
114+ // Allow http/https only for non-data URIs
111115 ::Microsoft::ReactNative::InputValidation::URLValidator::ValidateURL (uri, {" http" , " https" });
112116 }
113117 } catch (const ::Microsoft::ReactNative::InputValidation::ValidationException &ex) {
@@ -140,8 +144,12 @@ void ImageLoader::getSizeWithHeaders(
140144 &&result) noexcept {
141145 // SDL Compliance: Validate URI for SSRF (P0 Critical - CVSS 7.8)
142146 try {
143- // Allow data: URIs and http/https only
144- if (uri.find (" data:" ) != 0 ) {
147+ if (uri.find (" data:" ) == 0 ) {
148+ // Validate data URI size to prevent DoS through memory exhaustion
149+ ::Microsoft::ReactNative::InputValidation::SizeValidator::ValidateSize (
150+ uri.length(), ::Microsoft::ReactNative::InputValidation::SizeValidator::MAX_DATA_URI_SIZE, "Data URI");
151+ } else {
152+ // Allow http/https only for non-data URIs
145153 ::Microsoft::ReactNative::InputValidation::URLValidator::ValidateURL (uri, {" http" , " https" });
146154 }
147155 } catch (const ::Microsoft::ReactNative::InputValidation::ValidationException &ex) {
@@ -172,8 +180,12 @@ void ImageLoader::getSizeWithHeaders(
172180void ImageLoader::prefetchImage (std::string uri, React::ReactPromise<bool > &&result) noexcept {
173181 // VALIDATE URI - file:// abuse PROTECTION (P0 Critical - CVSS 7.8)
174182 try {
175- // Allow data: URIs and http/https only
176- if (uri.find (" data:" ) != 0 ) {
183+ if (uri.find (" data:" ) == 0 ) {
184+ // Validate data URI size to prevent DoS through memory exhaustion
185+ ::Microsoft::ReactNative::InputValidation::SizeValidator::ValidateSize (
186+ uri.length(), ::Microsoft::ReactNative::InputValidation::SizeValidator::MAX_DATA_URI_SIZE, "Data URI");
187+ } else {
188+ // Allow http/https only for non-data URIs
177189 ::Microsoft::ReactNative::InputValidation::URLValidator::ValidateURL (uri, {" http" , " https" });
178190 }
179191 } catch (const ::Microsoft::ReactNative::InputValidation::ValidationException &ex) {
@@ -192,8 +204,12 @@ void ImageLoader::prefetchImageWithMetadata(
192204 React::ReactPromise<bool > &&result) noexcept {
193205 // SDL Compliance: Validate URI for SSRF (P0 Critical - CVSS 7.8)
194206 try {
195- // Allow data: URIs and http/https only
196- if (uri.find (" data:" ) != 0 ) {
207+ if (uri.find (" data:" ) == 0 ) {
208+ // Validate data URI size to prevent DoS through memory exhaustion
209+ ::Microsoft::ReactNative::InputValidation::SizeValidator::ValidateSize (
210+ uri.length(), ::Microsoft::ReactNative::InputValidation::SizeValidator::MAX_DATA_URI_SIZE, "Data URI");
211+ } else {
212+ // Allow http/https only for non-data URIs
197213 ::Microsoft::ReactNative::InputValidation::URLValidator::ValidateURL (uri, {" http" , " https" });
198214 }
199215 } catch (const ::Microsoft::ReactNative::InputValidation::ValidationException &ex) {
0 commit comments