Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http): prevent POST request from being proxied #7395

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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