Skip to content

Commit 6a96ce7

Browse files
authored
fix(http): prevent POST request from being proxied (#7402)
1 parent aed075f commit 6a96ce7

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

android/capacitor/src/main/assets/native-bridge.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,11 @@ var nativeBridge = (function (exports) {
502502
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
503503
return win.CapacitorWebFetch(resource, options);
504504
}
505-
if (!(options === null || options === void 0 ? void 0 : options.method) ||
506-
options.method.toLocaleUpperCase() === 'GET' ||
507-
options.method.toLocaleUpperCase() === 'HEAD' ||
508-
options.method.toLocaleUpperCase() === 'OPTIONS' ||
509-
options.method.toLocaleUpperCase() === 'TRACE') {
505+
const { method } = request;
506+
if (method.toLocaleUpperCase() === 'GET' ||
507+
method.toLocaleUpperCase() === 'HEAD' ||
508+
method.toLocaleUpperCase() === 'OPTIONS' ||
509+
method.toLocaleUpperCase() === 'TRACE') {
510510
if (typeof resource === 'string') {
511511
return await win.CapacitorWebFetch(createProxyUrl(resource, win), options);
512512
}
@@ -518,8 +518,7 @@ var nativeBridge = (function (exports) {
518518
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
519519
console.time(tag);
520520
try {
521-
// intercept request & pass to the bridge
522-
const { body, method } = request;
521+
const { body } = request;
523522
const optionHeaders = Object.fromEntries(request.headers.entries());
524523
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || body || undefined, optionHeaders['Content-Type'] || optionHeaders['content-type']);
525524
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {

core/native-bridge.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,12 @@ const initBridge = (w: any): void => {
551551
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
552552
return win.CapacitorWebFetch(resource, options);
553553
}
554-
554+
const { method } = request;
555555
if (
556-
!options?.method ||
557-
options.method.toLocaleUpperCase() === 'GET' ||
558-
options.method.toLocaleUpperCase() === 'HEAD' ||
559-
options.method.toLocaleUpperCase() === 'OPTIONS' ||
560-
options.method.toLocaleUpperCase() === 'TRACE'
556+
method.toLocaleUpperCase() === 'GET' ||
557+
method.toLocaleUpperCase() === 'HEAD' ||
558+
method.toLocaleUpperCase() === 'OPTIONS' ||
559+
method.toLocaleUpperCase() === 'TRACE'
561560
) {
562561
if (typeof resource === 'string') {
563562
return await win.CapacitorWebFetch(
@@ -576,8 +575,7 @@ const initBridge = (w: any): void => {
576575
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
577576
console.time(tag);
578577
try {
579-
// intercept request & pass to the bridge
580-
const { body, method } = request;
578+
const { body } = request;
581579
const optionHeaders = Object.fromEntries(request.headers.entries());
582580
const {
583581
data: requestData,

ios/Capacitor/Capacitor/assets/native-bridge.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,11 @@ var nativeBridge = (function (exports) {
502502
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
503503
return win.CapacitorWebFetch(resource, options);
504504
}
505-
if (!(options === null || options === void 0 ? void 0 : options.method) ||
506-
options.method.toLocaleUpperCase() === 'GET' ||
507-
options.method.toLocaleUpperCase() === 'HEAD' ||
508-
options.method.toLocaleUpperCase() === 'OPTIONS' ||
509-
options.method.toLocaleUpperCase() === 'TRACE') {
505+
const { method } = request;
506+
if (method.toLocaleUpperCase() === 'GET' ||
507+
method.toLocaleUpperCase() === 'HEAD' ||
508+
method.toLocaleUpperCase() === 'OPTIONS' ||
509+
method.toLocaleUpperCase() === 'TRACE') {
510510
if (typeof resource === 'string') {
511511
return await win.CapacitorWebFetch(createProxyUrl(resource, win), options);
512512
}
@@ -518,8 +518,7 @@ var nativeBridge = (function (exports) {
518518
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
519519
console.time(tag);
520520
try {
521-
// intercept request & pass to the bridge
522-
const { body, method } = request;
521+
const { body } = request;
523522
const optionHeaders = Object.fromEntries(request.headers.entries());
524523
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || body || undefined, optionHeaders['Content-Type'] || optionHeaders['content-type']);
525524
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {

0 commit comments

Comments
 (0)