Skip to content

Commit b2d8eb3

Browse files
authored
Document trusted patterns for semgrep (#16423)
* chore: annotate trusted semgrep patterns * chore: remove changeset from semgrep annotation PR
1 parent 208b452 commit b2d8eb3

8 files changed

Lines changed: 16 additions & 0 deletions

File tree

packages/astro-prism/src/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export function addAstro(Prism: typeof import('prismjs')) {
3131
.replace(/<SPREAD>/g, function () {
3232
return spread;
3333
});
34+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
35+
// Built from static Prism token sources, not user input.
3436
return RegExp(source, flags);
3537
}
3638

packages/astro/src/core/app/manifest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export function deserializeRouteData(rawRouteData: SerializedRouteData): RouteDa
8888
return {
8989
route: rawRouteData.route,
9090
type: rawRouteData.type,
91+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
92+
// This pattern is serialized from Astro's own route manifest.
9193
pattern: new RegExp(rawRouteData.pattern),
9294
params: rawRouteData.params,
9395
component: rawRouteData.component,

packages/astro/src/core/routing/pattern.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export function getPattern(
4141
if (addTrailingSlash === 'never' && base !== '/') {
4242
initial = '';
4343
}
44+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
45+
// The pattern is assembled from escaped route segments generated by Astro.
4446
return new RegExp(`^${pathname || initial}${trailing}`);
4547
}
4648

packages/astro/src/prefetch/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ function onPageLoad(cb: () => void) {
332332
function appendSpeculationRules(url: string, eagerness: PrefetchOptions['eagerness']) {
333333
const script = document.createElement('script');
334334
script.type = 'speculationrules';
335+
// nosemgrep: javascript.lang.security.audit.unknown-value-with-script-tag.unknown-value-with-script-tag
336+
// This writes JSON via textContent, not executable JavaScript source.
335337
script.textContent = JSON.stringify({
336338
prerender: [
337339
{

packages/astro/src/vite-plugin-config-alias/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const getViteResolveAlias = (settings: AstroSettings) => {
8989
// id is already the wildcard part (e.g., 'extra.css' for '@styles/*')
9090
// resolvedValues still have the * in them, so replace * with id
9191
for (const resolvedValue of resolvedValues) {
92+
// nosemgrep: javascript.lang.security.audit.incomplete-sanitization.incomplete-sanitization
93+
// `id` is the wildcard capture from the alias match and only substitutes the tsconfig `*`.
9294
const resolved = resolvedValue.replace('*', id);
9395
const stats = fs.statSync(resolved, { throwIfNoEntry: false });
9496
if (stats && stats.isFile()) {

packages/integrations/netlify/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export function remotePatternToRegex(
9595
regexStr += '([?][^#]*)?';
9696
}
9797
try {
98+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
99+
// This only validates the generated pattern before handing it to Netlify.
98100
new RegExp(regexStr);
99101
} catch {
100102
logger.warn(

packages/integrations/partytown/src/sirv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ export default function (dir, opts = {}) {
183183
if (opts.dotfiles) ignores.push(/\/\.\w/);
184184
else ignores.push(/\/\.well-known/);
185185
[].concat(opts.ignores || []).forEach((x) => {
186+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
187+
// This mirrors sirv's developer-supplied ignore patterns.
186188
ignores.push(new RegExp(x, 'i'));
187189
});
188190
}

packages/integrations/preact/src/static-html.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type Props = {
1616
const StaticHtml = ({ value, name, hydrate = true }: Props) => {
1717
if (!value) return null;
1818
const tagName = hydrate ? 'astro-slot' : 'astro-static-slot';
19+
// nosemgrep: typescript.react.security.audit.react-dangerouslysetinnerhtml.react-dangerouslysetinnerhtml
20+
// Astro passes framework-rendered HTML through this adapter boundary intentionally.
1921
return h(tagName, { name, dangerouslySetInnerHTML: { __html: value } });
2022
};
2123

0 commit comments

Comments
 (0)