Skip to content

Commit 434dbc3

Browse files
fix: replace internal redirects with 404 responses across workflow pages and block .json path access
1 parent 064febf commit 434dbc3

5 files changed

Lines changed: 70 additions & 7 deletions

File tree

site/src/pages/[locale]/workflows/[slug].astro

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ Astro.response.headers.set('CDN-Cache-Control', 'public, max-age=60, stale-while
3535
3636
const { locale, slug } = Astro.params;
3737
38+
if (Astro.url.pathname.endsWith('.json/')) {
39+
return new Response(null, {
40+
status: 404,
41+
statusText: 'Not Found',
42+
});
43+
}
44+
3845
// Validate locale
3946
if (!locale || !LOCALES.includes(locale as Locale) || locale === DEFAULT_LOCALE) {
4047
return Astro.redirect('/workflows/');
@@ -61,7 +68,10 @@ if (detailShareId) {
6168
if (!is404) {
6269
console.error('Hub API error on ISR detail:', err);
6370
}
64-
return Astro.redirect(`/${locale}/workflows/`);
71+
return new Response(null, {
72+
status: 404,
73+
statusText: 'Not Found',
74+
});
6575
}
6676
}
6777
@@ -130,7 +140,10 @@ try {
130140
// link): no profile and no workflows — redirect instead of rendering a page
131141
// that would title itself "<slug> (@<slug>)" and get indexed by Google.
132142
if (!isDetailPage && !profileFound && serialized.length === 0) {
133-
return Astro.redirect(`/${locale}/workflows/`);
143+
return new Response(null, {
144+
status: 404,
145+
statusText: 'Not Found',
146+
});
134147
}
135148
136149
const canonicalUrl = absoluteUrl(`/workflows/${slug}/`);

site/src/pages/[locale]/workflows/category/[type].astro

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ const categoryTranslationKeys: Record<MediaType, string> = {
3131
3232
const { locale, type } = Astro.params;
3333
34+
if (Astro.url.pathname.endsWith('.json/')) {
35+
return new Response(null, {
36+
status: 404,
37+
statusText: 'Not Found',
38+
});
39+
}
40+
3441
// Validate locale
3542
if (!locale || !LOCALES.includes(locale as Locale) || locale === DEFAULT_LOCALE) {
3643
return Astro.redirect(`/workflows/category/${type || ''}/`);
3744
}
3845
3946
// Validate type
4047
if (!type || !validTypes.includes(type as MediaType)) {
41-
return Astro.redirect(`/${locale}/workflows/`);
48+
return new Response(null, {
49+
status: 404,
50+
statusText: 'Not Found',
51+
});
4252
}
4353
4454
const typedLocale = locale as Locale;
@@ -51,6 +61,13 @@ const description = t('meta.description', typedLocale);
5161
const allSerialized = await loadSerializedTemplates(() => getCollection('templates'));
5262
const templates = allSerialized.filter((tmpl) => tmpl.mediaType === mediaType);
5363
64+
if (templates.length === 0) {
65+
return new Response(null, {
66+
status: 404,
67+
statusText: 'Not Found',
68+
});
69+
}
70+
5471
const basePath = categoryPath(mediaType);
5572
const canonicalUrl = absoluteUrl(localizeUrl(basePath, typedLocale));
5673

site/src/pages/[locale]/workflows/model/[name].astro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import { loadSerializedTemplates, type SerializedTemplate } from '../../../../li
2323
2424
const { locale, name } = Astro.params;
2525
26+
if (Astro.url.pathname.endsWith('.json/')) {
27+
return new Response(null, {
28+
status: 404,
29+
statusText: 'Not Found',
30+
});
31+
}
32+
2633
// Validate locale
2734
if (!locale || !LOCALES.includes(locale as Locale) || locale === DEFAULT_LOCALE) {
2835
return Astro.redirect(`/workflows/model/${name || ''}/`);
@@ -38,7 +45,10 @@ const matchingTemplates = allTemplates.filter((tmpl) =>
3845
);
3946
4047
if (matchingTemplates.length === 0) {
41-
return Astro.redirect(`/${locale}/workflows/`);
48+
return new Response(null, {
49+
status: 404,
50+
statusText: 'Not Found',
51+
});
4252
}
4353
4454
// Get display name from the first matching model

site/src/pages/[locale]/workflows/tag/[tag].astro

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import { loadSerializedTemplates, type SerializedTemplate } from '../../../../li
2222
2323
const { locale, tag } = Astro.params;
2424
25+
if (Astro.url.pathname.endsWith('.json/')) {
26+
return new Response(null, {
27+
status: 404,
28+
statusText: 'Not Found',
29+
});
30+
}
31+
2532
// Validate locale
2633
if (!locale || !LOCALES.includes(locale as Locale) || locale === DEFAULT_LOCALE) {
2734
return Astro.redirect(`/workflows/tag/${tag || ''}/`);
@@ -37,7 +44,10 @@ const matchingTemplates = allTemplates.filter((tmpl) =>
3744
);
3845
3946
if (matchingTemplates.length === 0) {
40-
return Astro.redirect(`/${locale}/workflows/`);
47+
return new Response(null, {
48+
status: 404,
49+
statusText: 'Not Found',
50+
});
4151
}
4252
4353
// Get display name from the first matching tag

site/src/pages/workflows/[username].astro

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Astro.response.headers.set(
3131
const { username: slugParam } = Astro.params;
3232
const locale = getLocaleFromPath(Astro.url.pathname);
3333
34+
if (Astro.url.pathname.endsWith('.json/')) {
35+
return new Response(null, {
36+
status: 404,
37+
statusText: 'Not Found',
38+
});
39+
}
40+
3441
if (!slugParam) {
3542
return Astro.redirect('/workflows/');
3643
}
@@ -50,7 +57,10 @@ if (detailShareId) {
5057
if (!is404) {
5158
console.error('Hub API error on ISR detail:', err);
5259
}
53-
return Astro.redirect('/workflows/');
60+
return new Response(null, {
61+
status: 404,
62+
statusText: 'Not Found',
63+
});
5464
}
5565
}
5666
@@ -97,7 +107,10 @@ try {
97107
// of rendering a page that would title itself "<slug> (@<slug>)" and get
98108
// indexed by Google.
99109
if (!isDetailPage && !profileFound && serialized.length === 0) {
100-
return Astro.redirect('/workflows/');
110+
return new Response(null, {
111+
status: 404,
112+
statusText: 'Not Found',
113+
});
101114
}
102115
103116
const canonicalUrl = absoluteUrl(`/workflows/${slugParam}/`);

0 commit comments

Comments
 (0)