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

Encode the URL before fetching it. #7934

Merged
merged 1 commit into from
Sep 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/strapi-plugin-upload/controllers/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
}

try {
const res = await fetch(ctx.query.url, {
const res = await fetch(new URL(ctx.query.url), {
headers: _.omit(ctx.request.headers, ['origin', 'host', 'authorization']),
});

Expand Down
42 changes: 42 additions & 0 deletions packages/strapi-plugin-upload/test/proxy.test.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

// Helpers.
const { registerAndLogin } = require('../../../test/helpers/auth');
const { createAuthRequest } = require('../../../test/helpers/request');

let rq;

describe('Upload plugin end to end tests', () => {
beforeAll(async () => {
const token = await registerAndLogin();
rq = createAuthRequest(token);
}, 60000);

describe('GET /upload/proxy => Proxy the file', () => {
test('Return the remote URL', async () => {
const res = await rq.get('/upload/proxy', {
qs: {
url: 'https://strapi.io/'
},
});
expect(res.statusCode).toBe(200);
});

test('Accept an url with utf-8 characters', async () => {
const res = await rq.get('/upload/proxy', {
qs: {
url: 'https://strapi.io/?foo=网'
},
});

expect(res.statusCode).toBe(200);
});

test('Return 400 with an invalid url', async () => {
const res = await rq.get('/upload/proxy');

expect(res.statusCode).toBe(400);
expect(res.body).toEqual('Invalid URL');
});
});
});