Skip to content

Commit

Permalink
fix(http): prevent POST request from being proxied (#7395)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Anderson <mark@ionic.io>
Co-authored-by: Dan Giralté <97970732+giralte-ionic@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 15, 2024
1 parent d2b5270 commit 7b8c352
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions android/capacitor/src/main/assets/native-bridge.js
Expand Up @@ -498,11 +498,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 @@ -514,7 +514,7 @@ var nativeBridge = (function (exports) {
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
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
13 changes: 6 additions & 7 deletions core/native-bridge.ts
Expand Up @@ -547,13 +547,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 @@ -573,7 +572,7 @@ const initBridge = (w: any): void => {
console.time(tag);

try {
const { body, method } = request;
const { body } = request;
const optionHeaders = Object.fromEntries(request.headers.entries());
const {
data: requestData,
Expand Down
12 changes: 6 additions & 6 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Expand Up @@ -498,11 +498,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 @@ -514,7 +514,7 @@ var nativeBridge = (function (exports) {
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`;
console.time(tag);
try {
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 7b8c352

Please sign in to comment.