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(vercel): clear artifacts from redirects #9287

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
log error and ignore for external redirects
  • Loading branch information
lilnasy committed Dec 8, 2023
commit aac50366a515dfec6869739714209dd37a37d271
1 change: 1 addition & 0 deletions packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type LoggerLabel =
| 'watch'
| 'middleware'
| 'preferences'
| 'redirects'
// SKIP_FORMAT: A special label that tells the logger not to apply any formatting.
// Useful for messages that are already formatted, like the server start message.
| 'SKIP_FORMAT';
Expand Down
13 changes: 13 additions & 0 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,19 @@ export function createRouteManifest(
.map(([{ dynamic, content }]) => (dynamic ? `[${content}]` : content))
.join('/')}`.toLowerCase();

{
let destination: string
if (typeof to === "string") {
destination = to
}
else {
destination = to.destination
}
if (destination.startsWith("http")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 'httpfoobar' a valid pathname destination? Do we enforce that the pathname starts with /? I guess not since this gets here. So should we be checking for http(s)://?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, we don't validate the paths much.

return logger.error('redirects', `Redirecting to an external URLs is not supported: ${from} -> ${to}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

This comment was marked as resolved.

}
}

const routeData: RouteData = {
type: 'redirect',
route,
Expand Down
9 changes: 9 additions & 0 deletions packages/astro/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Astro.redirect', () => {
adapter: testAdapter(),
redirects: {
'/api/redirect': '/test',
'/external/redirect': 'https://example.com/',
},
});
await fixture.build();
Expand All @@ -27,6 +28,14 @@ describe('Astro.redirect', () => {
expect(response.headers.get('location')).to.equal('/login');
});

it('Ignores external redirect', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/external/redirect');
const response = await app.render(request);
expect(response.status).to.equal(404);
expect(response.headers.get('location')).to.equal(null);
});

it('Warns when used inside a component', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/late');
Expand Down