A development host is kept out of search engines without IAPL_NOINDEX (developmentNoindex, default on)

Separate from the mail rule so that it can be taken or left. A site whose address matches
iapl({ developmentHosts }) - built in: *.dev.netscale.pl - is noindex with no env: robots.txt disallows
everything, pages carry noindex, IndexNow sends nothing, buildSecurityHeaders() adds X-Robots-Tag. Nothing
kept a development copy out of search engines until now unless somebody set the variable.

- iapl({ developmentNoindex: false }) switches it off for the project, IAPL_NOINDEX=0 for one environment
- buildSecurityHeaders({ developmentHosts, serverUrl }): next.config runs before the plugin
- the mail rule keeps its own two signals: the development pattern, and the variable itself
- changelog "what changes on upgrade", deployment.md, security.md, AGENT.md, skills

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 10:31:03 +01:00
co-authored by Claude Fable 5.2
parent 14abf369da
commit bc3aac249f
23 changed files with 215 additions and 24 deletions
+3 -2
View File
@@ -5,7 +5,7 @@ import { randomBytes } from 'node:crypto'
import type { RelayOptions, ResolvedRelayOptions } from './options.js'
import { PLUGIN_VERSION } from '../../../version.js'
import { isSiteNoindex } from '../../seo/siteNoindex.js'
import { noindexEnv } from '../../seo/siteNoindex.js'
import { matchDevelopmentHost } from '../../shared/developmentHosts.js'
import { type RelayAnswer, type RelayRefusal, relayRequest } from './client.js'
import { RELAY_CONFIRM_PATH, RELAY_DEFAULTS, RELAY_PRODUCT, type RelayStatusCode, relayStatusFor } from './constants.js'
@@ -108,7 +108,8 @@ export type NonPublicSignal = { by: 'development-host'; pattern: string } | { by
export function siteNonPublicSignal(payload: BasePayload, options: Pick<RelayOptions, 'developmentHosts' | 'host'>): NonPublicSignal | null {
const pattern = matchDevelopmentHost(relayHost(payload, options), options.developmentHosts ?? pluginDevelopmentHosts(payload))
if (pattern) {return { by: 'development-host', pattern }}
return isSiteNoindex() ? { by: 'noindex' } : null
// the variable itself: whether a development host is ALSO kept out of search engines is another question
return noindexEnv() === true ? { by: 'noindex' } : null
}
/** Is this site a non-public copy (`siteNonPublicSignal` as a yes or no)? */
+15 -2
View File
@@ -1,6 +1,7 @@
import type { BuildCspArgs } from './buildCsp.js'
import { isSiteNoindex } from '../seo/siteNoindex.js'
import { DEFAULT_DEVELOPMENT_HOSTS } from '../shared/developmentHosts.js'
import { buildCspHeaders } from './buildCsp.js'
/**
@@ -29,6 +30,14 @@ export type BuildSecurityHeadersArgs = {
* reports, then `mode: 'enforce'` (the only change). See docs/security.md.
*/
csp?: BuildCspArgs | false
/**
* Development-host patterns for the noindex header: a site whose address (`serverUrl`) matches gets
* `X-Robots-Tag: noindex, nofollow` without `IAPL_NOINDEX`. Default: the plugin's built-in list
* (`DEFAULT_DEVELOPMENT_HOSTS`, `['*.dev.netscale.pl']`). `next.config` runs before the plugin, so a
* project that changed `iapl({ developmentHosts })` passes the same list here; `false` = the variable
* alone decides.
*/
developmentHosts?: false | string[]
/**
* X-Frame-Options value. 'DENY' (default) blocks all framing; 'SAMEORIGIN'
* allows same-origin framing. Note: CSP frame-ancestors supersedes this in
@@ -56,6 +65,8 @@ export type BuildSecurityHeadersArgs = {
permissionsPolicy?: null | string
/** Referrer-Policy. Default 'strict-origin-when-cross-origin' (browser default, explicit). */
referrerPolicy?: null | string
/** The site's address, for `developmentHosts`. Default: `NEXT_PUBLIC_SERVER_URL`. */
serverUrl?: string
}
/**
@@ -93,7 +104,9 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
hstsPreload = false,
permissionsPolicy = 'camera=(), microphone=(), geolocation=()',
referrerPolicy = 'strict-origin-when-cross-origin',
serverUrl,
} = args
const developmentHosts = args.developmentHosts ?? DEFAULT_DEVELOPMENT_HOSTS
const headers: SecurityHeader[] = []
@@ -124,8 +137,8 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
headers.push({ key: 'Cross-Origin-Opener-Policy', value: coop })
}
// Staging / preview (IAPL_NOINDEX=1): keep every response out of search engines.
if (isSiteNoindex()) {
// Staging / preview (IAPL_NOINDEX=1) or a development host: keep every response out of search engines.
if (isSiteNoindex({ developmentHosts, host: serverUrl })) {
headers.push({ key: 'X-Robots-Tag', value: 'noindex, nofollow' })
}
+1 -1
View File
@@ -213,7 +213,7 @@ export function buildMetadata({
// robots: noindex pages are excluded (follow keeps link authority). Indexed
// pages get generous snippet/preview limits so Google can show rich results
// (long snippets, large image previews, full video previews).
...(isSiteNoindex()
...(isSiteNoindex({ host: origin })
? { robots: { follow: false, index: false } }
: noindex || meta?.noindex
? { robots: { follow: true, index: false } }
+2 -2
View File
@@ -140,8 +140,8 @@ export function buildRobots({
sitemap = true,
}: BuildRobotsArgs): RobotsRules {
const origin = baseUrl.replace(/\/$/, '')
// Staging / preview (IAPL_NOINDEX=1): nothing may be crawled.
if (isSiteNoindex()) {return { rules: { disallow: ['/'], userAgent: '*' } }}
// Staging / preview (IAPL_NOINDEX=1) or a development host (iapl({ developmentHosts })): nothing may be crawled.
if (isSiteNoindex({ host: origin })) {return { rules: { disallow: ['/'], userAgent: '*' } }}
const defaults = [...(adminRoute ? [adminRoute] : []), '/api']
const paramRules = disallowParams
+1 -1
View File
@@ -87,7 +87,7 @@ export function createIndexNowKeyRoute({ getCachedPayload }: { getCachedPayload:
*/
function publicOrigin(baseUrl?: string): null | string {
const origin = (baseUrl ?? process.env.NEXT_PUBLIC_SERVER_URL ?? '').replace(/\/$/, '')
if (isSiteNoindex()) {return null}
if (isSiteNoindex({ host: origin })) {return null}
if (process.env.NODE_ENV !== 'production' || !/^https:\/\//i.test(origin)) {return null}
if (/localhost|127\.0\.0\.1|\.local\b|\.test\b/i.test(origin)) {return null}
return origin
+38 -8
View File
@@ -1,19 +1,49 @@
import { isDevelopmentHost, noindexDevelopmentHosts } from '../shared/developmentHosts.js'
import { readEnv } from '../shared/envName.js'
/**
* Whole-site noindex for staging, previews and test copies: set IAPL_NOINDEX=1
* in that environment's env (the old spelling IPAL_NOINDEX is still read). Then robots.txt disallows everything, every page
* gets `robots: noindex, nofollow`, and buildSecurityHeaders adds
* `X-Robots-Tag: noindex, nofollow` to every response (files and API too).
* Production never sets it — a forgotten staging copy indexed by Google is a
* duplicate of the real site.
* Whole-site noindex for development, staging, preview and test copies. Then robots.txt disallows everything,
* every page gets `robots: noindex, nofollow`, buildSecurityHeaders adds `X-Robots-Tag: noindex, nofollow` to
* every response (files and API too), and IndexNow sends nothing.
*
* Two ways in:
* - `IAPL_NOINDEX=1` in that environment's env (the old spelling IPAL_NOINDEX is still read);
* - by host, with no env: the site's address (`NEXT_PUBLIC_SERVER_URL`) matches a development pattern —
* `iapl({ developmentHosts })`, built in `*.dev.netscale.pl`. A development copy indexed by Google is a
* duplicate of the real site, and nothing else keeps it out.
* `IAPL_NOINDEX=0` (or `false`, `no`, `off`) says otherwise for one environment; `iapl({ developmentNoindex:
* false })` switches the host rule off for the project. Production never sets the variable and is on no
* development host.
*/
/** The variable's name before 1.17.0. Still read; kept under this constant so `process.env[SITE_NOINDEX_ENV]` in a project means what it meant. */
export const SITE_NOINDEX_ENV = 'IPAL_NOINDEX'
/** The variable's name since 1.17.0. Read it with `isSiteNoindex()` or `readEnv(IAPL_SITE_NOINDEX_ENV)`, which fall back to the old one. */
export const IAPL_SITE_NOINDEX_ENV = 'IAPL_NOINDEX'
export function isSiteNoindex(): boolean {
/** What the variable says: `true` (1 / true / yes), `false` (0 / false / no / off), or `undefined` when it says nothing. */
export function noindexEnv(): boolean | undefined {
const v = readEnv(IAPL_SITE_NOINDEX_ENV)?.trim().toLowerCase()
return v === '1' || v === 'true' || v === 'yes'
if (v === '1' || v === 'true' || v === 'yes') {return true}
if (v === '0' || v === 'false' || v === 'no' || v === 'off') {return false}
return undefined
}
export type SiteNoindexArgs = {
/** The development patterns to go by; `false` = the variable alone decides. Default: the plugin's list. */
developmentHosts?: false | readonly string[]
/** The site's address or host. Default: `NEXT_PUBLIC_SERVER_URL`. */
host?: null | string
}
/** Which signal makes the site noindex: the variable, its development host, or nothing. */
export function siteNoindexSignal(args: SiteNoindexArgs = {}): 'development-host' | 'env' | null {
const env = noindexEnv()
if (env !== undefined) {return env ? 'env' : null}
const patterns = args.developmentHosts ?? noindexDevelopmentHosts()
if (patterns === false) {return null}
return isDevelopmentHost(args.host || process.env.NEXT_PUBLIC_SERVER_URL, patterns) ? 'development-host' : null
}
export function isSiteNoindex(args: SiteNoindexArgs = {}): boolean {
return siteNoindexSignal(args) !== null
}
+18
View File
@@ -42,3 +42,21 @@ export function matchDevelopmentHost(host: null | string | undefined, patterns:
/** Is `host` a development address (`matchDevelopmentHost` as a yes or no)? */
export const isDevelopmentHost = (host: null | string | undefined, patterns: readonly string[] = DEFAULT_DEVELOPMENT_HOSTS): boolean =>
matchDevelopmentHost(host, patterns) !== null
// What `iapl({ developmentHosts, developmentNoindex })` set for this process — read by the helpers that run
// without a Payload config at hand (robots, metadata, IndexNow). `next.config` runs before the plugin: there,
// `buildSecurityHeaders({ developmentHosts })` takes the same list when the project changed it.
let configured: { hosts?: readonly string[]; noindex?: boolean } = {}
/** Called by the plugin with its options; a later call replaces the earlier one. */
export function configureDevelopmentHosts(options: { hosts?: readonly string[]; noindex?: boolean } = {}): void {
configured = { ...(options.hosts ? { hosts: [...options.hosts] } : {}), ...(options.noindex === false ? { noindex: false } : {}) }
}
/**
* The patterns whose hosts are kept out of search engines by default: the plugin's development hosts, or
* `false` when the project switched that off (`iapl({ developmentNoindex: false })`).
*/
export function noindexDevelopmentHosts(): false | readonly string[] {
return configured.noindex === false ? false : (configured.hosts ?? DEFAULT_DEVELOPMENT_HOSTS)
}