Files
site/node_modules/sitemap/dist/lib/constants.js
T

82 lines
3.1 KiB
JavaScript

/*!
* Sitemap
* Copyright(c) 2011 Eugene Kalinin
* MIT Licensed
*/
/**
* Shared constants used across the sitemap library
* This file serves as a single source of truth for limits and validation patterns
*/
/**
* Security limits for sitemap generation and parsing
*
* These limits are based on:
* - sitemaps.org protocol specification
* - Security best practices to prevent DoS and injection attacks
* - Google's sitemap extension specifications
*
* @see https://www.sitemaps.org/protocol.html
* @see https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap
*/
export const LIMITS = {
// URL constraints per sitemaps.org spec
MAX_URL_LENGTH: 2048,
URL_PROTOCOL_REGEX: /^https?:\/\//i,
// Sitemap size limits per sitemaps.org spec
MIN_SITEMAP_ITEM_LIMIT: 1,
MAX_SITEMAP_ITEM_LIMIT: 50000,
// Priority bounds per sitemaps.org spec
MIN_PRIORITY: 0,
MAX_PRIORITY: 1,
// A priority string normalizeURL converts to a number: plain decimal only,
// so hex, binary and exponent forms that Number() accepts stay invalid
PRIORITY_STRING_REGEX: /^\s*(?:\d+\.?\d*|\.\d+)\s*$/,
// Video value bounds per Google spec
MIN_VIDEO_DURATION: 0,
MAX_VIDEO_DURATION: 28800, // 8 hours
MIN_VIDEO_RATING: 0,
MAX_VIDEO_RATING: 5,
MIN_VIDEO_VIEW_COUNT: 0,
// Video field length constraints per Google spec
MAX_VIDEO_TITLE_LENGTH: 100,
MAX_VIDEO_DESCRIPTION_LENGTH: 2048,
MAX_VIDEO_CATEGORY_LENGTH: 256,
MAX_TAGS_PER_VIDEO: 32,
// News field length constraints per Google spec
MAX_NEWS_TITLE_LENGTH: 200,
MAX_NEWS_NAME_LENGTH: 256,
// Image field length constraints per Google spec
MAX_IMAGE_CAPTION_LENGTH: 512,
MAX_IMAGE_TITLE_LENGTH: 512,
// Limits on number of items per URL entry
MAX_IMAGES_PER_URL: 1000,
MAX_VIDEOS_PER_URL: 100,
MAX_LINKS_PER_URL: 100,
/**
* Total entries in a sitemap.
* @deprecated Unused; the parsers cap entries at MAX_SITEMAP_ITEM_LIMIT
* (same value), overridable with their `maxEntries` option.
*/
MAX_URL_ENTRIES: 50000,
// Date validation - ISO 8601 / W3C format
ISO_DATE_REGEX: /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?([+-]\d{2}:\d{2}|Z)?)?$/,
// Custom namespace limits to prevent DoS
MAX_CUSTOM_NAMESPACES: 20,
MAX_NAMESPACE_LENGTH: 512,
// Cap on buffered character data per element in the parser, matching sax's
// default buffer size. Larger values are dropped to bound memory use.
MAX_PARSER_CHAR_DATA_LENGTH: 65536,
// Cap on stored parser errors to prevent memory DoS (BB-03)
// Errors beyond this limit are counted in errorCount but not retained as objects
MAX_PARSER_ERRORS: 100,
};
/**
* Default maximum number of items in each sitemap XML file, shared by
* SitemapAndIndexStream, simpleSitemapAndIndex and the CLI.
* Set below the 50,000 max to leave headroom under the 50MB uncompressed
* file-size limit, which entries with images, video or news can approach.
*
* @see https://www.sitemaps.org/protocol.html#index
*/
export const DEFAULT_SITEMAP_ITEM_LIMIT = 45000;