Skip to content

Commit

Permalink
fix(http): prevent POST request from being proxied (#7402)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 15, 2024
1 parent aed075f commit 6a96ce7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
13 changes: 6 additions & 7 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ var nativeBridge = (function (exports) {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}
if (!(options === null || options === void 0 ? void 0 : options.method) ||
options.method.toLocaleUpperCase() === 'GET' ||
options.method.toLocaleUpperCase() === 'HEAD' ||
options.method.toLocaleUpperCase() === 'OPTIONS' ||
options.method.toLocaleUpperCase() === 'TRACE') {
const { method } = request;
if (method.toLocaleUpperCase() === 'GET' ||
method.toLocaleUpperCase() === 'HEAD' ||
method.toLocaleUpperCase() === 'OPTIONS' ||
method.toLocaleUpperCase() === 'TRACE') {
if (typeof resource === 'string') {
return await win.CapacitorWebFetch(createProxyUrl(resource, win), options);
}
Expand All @@ -518,8 +518,7 @@ var nativeBridge = (function (exports) {
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
// intercept request & pass to the bridge
const { body, method } = request;
const { body } = request;
const optionHeaders = Object.fromEntries(request.headers.entries());
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || body || undefined, optionHeaders['Content-Type'] || optionHeaders['content-type']);
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
Expand Down
14 changes: 6 additions & 8 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,12 @@ const initBridge = (w: any): void => {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}

const { method } = request;
if (
!options?.method ||
options.method.toLocaleUpperCase() === 'GET' ||
options.method.toLocaleUpperCase() === 'HEAD' ||
options.method.toLocaleUpperCase() === 'OPTIONS' ||
options.method.toLocaleUpperCase() === 'TRACE'
method.toLocaleUpperCase() === 'GET' ||
method.toLocaleUpperCase() === 'HEAD' ||
method.toLocaleUpperCase() === 'OPTIONS' ||
method.toLocaleUpperCase() === 'TRACE'
) {
if (typeof resource === 'string') {
return await win.CapacitorWebFetch(
Expand All @@ -576,8 +575,7 @@ const initBridge = (w: any): void => {
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
// intercept request & pass to the bridge
const { body, method } = request;
const { body } = request;
const optionHeaders = Object.fromEntries(request.headers.entries());
const {
data: requestData,
Expand Down
13 changes: 6 additions & 7 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ var nativeBridge = (function (exports) {
if (request.url.startsWith(`${cap.getServerUrl()}/`)) {
return win.CapacitorWebFetch(resource, options);
}
if (!(options === null || options === void 0 ? void 0 : options.method) ||
options.method.toLocaleUpperCase() === 'GET' ||
options.method.toLocaleUpperCase() === 'HEAD' ||
options.method.toLocaleUpperCase() === 'OPTIONS' ||
options.method.toLocaleUpperCase() === 'TRACE') {
const { method } = request;
if (method.toLocaleUpperCase() === 'GET' ||
method.toLocaleUpperCase() === 'HEAD' ||
method.toLocaleUpperCase() === 'OPTIONS' ||
method.toLocaleUpperCase() === 'TRACE') {
if (typeof resource === 'string') {
return await win.CapacitorWebFetch(createProxyUrl(resource, win), options);
}
Expand All @@ -518,8 +518,7 @@ var nativeBridge = (function (exports) {
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
// intercept request & pass to the bridge
const { body, method } = request;
const { body } = request;
const optionHeaders = Object.fromEntries(request.headers.entries());
const { data: requestData, type, headers, } = await convertBody((options === null || options === void 0 ? void 0 : options.body) || body || undefined, optionHeaders['Content-Type'] || optionHeaders['content-type']);
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
Expand Down

0 comments on commit 6a96ce7

Please sign in to comment.