feat: harden operated production release

This commit is contained in:
jwinterm
2026-07-22 12:56:00 -04:00
parent dfe4d1ad97
commit 91f139eeaa
44 changed files with 4500 additions and 653 deletions
+22 -5
View File
@@ -6,7 +6,12 @@
* actions unless the browser echoes the current policy version and every required acknowledgement.
*/
const DEFAULT_POLICY_VERSION = '2026-07-21';
const {
SOURCE_SOFTWARE,
getOperatedProductProfile
} = require('./operatedProductProfiles');
const DEFAULT_POLICY_VERSION = '2026-07-22';
const DEFAULT_MINIMUM_AGE = 18;
const ALLOWED_CONTACT_PROTOCOLS = new Set(['https:', 'http:', 'mailto:']);
const ACKNOWLEDGEMENT_KEYS = new Set([
@@ -73,6 +78,7 @@ function paidAcknowledgementRequired(env, gameModeManager) {
}
function buildCommerceDisclosure(gameModeManager, env = process.env) {
const operatedProduct = getOperatedProductProfile(env);
const cryptoType = String(gameModeManager?.cryptoType || env.CRYPTO_TYPE || 'WOW').toUpperCase();
const network = String(gameModeManager?.network || env.MONERO_NETWORK || 'mainnet').toLowerCase();
const isTestNetwork = Boolean(gameModeManager?.isTestNetwork)
@@ -92,7 +98,17 @@ function buildCommerceDisclosure(gameModeManager, env = process.env) {
&& Boolean(gameModeManager?.payoutsEnabled);
const anyPayouts = directPayouts || creditsPayouts || cryptoMatchPayouts;
const currencyLabel = String(gameModeManager?.currencyLabel || (isTestNetwork ? `s${cryptoType}` : cryptoType));
const operatorContactUrl = safeContactUrl(env.OPERATOR_CONTACT_URL);
const operatorContactUrl = safeContactUrl(
operatedProduct?.operatorContactUrl || env.OPERATOR_CONTACT_URL
);
const operatorName = operatedProduct?.operatorName
|| String(env.OPERATOR_NAME || '').trim()
|| 'Site operator (identity not configured)';
const operatorContactLabel = operatedProduct?.operatorContactLabel
|| String(env.OPERATOR_CONTACT_LABEL || '').trim()
|| (operatorContactUrl
? operatorContactUrl.replace(/^mailto:/, '')
: 'Operator contact is not configured');
return Object.freeze({
policyVersion: String(env.LEGAL_POLICY_VERSION || DEFAULT_POLICY_VERSION).trim(),
@@ -100,11 +116,12 @@ function buildCommerceDisclosure(gameModeManager, env = process.env) {
minimumAge: minimumAge(env),
paidAcknowledgementRequired: paidAcknowledgementRequired(env, gameModeManager),
operator: Object.freeze({
name: String(env.OPERATOR_NAME || '').trim() || 'Site operator (identity not configured)',
name: operatorName,
contactUrl: operatorContactUrl,
contactLabel: String(env.OPERATOR_CONTACT_LABEL || '').trim()
|| (operatorContactUrl ? operatorContactUrl.replace(/^mailto:/, '') : 'Operator contact is not configured')
contactLabel: operatorContactLabel
}),
operatedProduct,
software: SOURCE_SOFTWARE,
service: Object.freeze({
gameName: String(gameModeManager?.gameName || 'Wowngeon'),
cryptoType,
+43
View File
@@ -9,6 +9,7 @@
const { isSupported, familyFor } = require('../chain/chainProfile');
const { resolveMatchRuleset } = require('../game/rulesets');
const money = require('../money/atomic');
const { validateOperatedProductProfile } = require('./operatedProductProfiles');
const {
PG_BIGINT_MAX,
cryptoRulesetSupported,
@@ -129,6 +130,8 @@ class EnvironmentValidator {
const walletRequired = paymentsEnabled || payoutMasterEnabled;
const cryptoType = String(env.CRYPTO_TYPE || config?.currency?.symbol || 'WOW').trim().toUpperCase();
const network = String(env.MONERO_NETWORK || 'mainnet').trim().toLowerCase();
const financialSinkUrl = String(env.FINANCIAL_EVENT_SINK_URL || '').trim();
const financialSinkToken = String(env.FINANCIAL_EVENT_SINK_TOKEN || '').trim();
if (env.GAME_MODE && env.PAYMENT_MODES) {
warnings.push('Both GAME_MODE and PAYMENT_MODES are set. PAYMENT_MODES takes precedence.');
@@ -229,6 +232,41 @@ class EnvironmentValidator {
this._pushEndpointTransportWarning(warnings, 'PRIMARY_WALLET_ENDPOINT', env.PRIMARY_WALLET_ENDPOINT);
this._pushEndpointTransportWarning(warnings, 'PRIMARY_RPC_ENDPOINT', env.PRIMARY_RPC_ENDPOINT);
// Accounting export is optional, but a partial or misleading configuration is not. The
// stagenet product intentionally suppresses its no-value test events instead of sending
// them to a real accounting sink.
if (Boolean(financialSinkUrl) !== Boolean(financialSinkToken)) {
errors.push('FINANCIAL_EVENT_SINK_URL and FINANCIAL_EVENT_SINK_TOKEN must be configured together.');
}
if (financialSinkUrl && financialSinkToken) {
try {
const endpoint = new URL(financialSinkUrl);
if (!['http:', 'https:'].includes(endpoint.protocol)) {
errors.push('FINANCIAL_EVENT_SINK_URL must use http:// or https://.');
}
if (endpoint.username || endpoint.password) {
errors.push('FINANCIAL_EVENT_SINK_URL must not embed credentials.');
}
if (production && endpoint.protocol !== 'https:') {
errors.push('FINANCIAL_EVENT_SINK_URL must use https:// in production.');
}
} catch (_) {
errors.push('FINANCIAL_EVENT_SINK_URL must be a valid URL.');
}
if (financialSinkToken.length < 32
|| PLACEHOLDER_SECRET.test(financialSinkToken)
|| new Set(financialSinkToken).size < 8) {
errors.push('FINANCIAL_EVENT_SINK_TOKEN must be a strong non-placeholder secret of at least 32 characters.');
}
if (network !== 'mainnet') {
errors.push('Financial event export must be unset on non-mainnet networks; test-network events are suppressed locally.');
}
const accountRef = String(env.FINANCIAL_EVENT_ACCOUNT_REF || 'wowngeon:receipts').trim();
if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(accountRef)) {
errors.push('FINANCIAL_EVENT_ACCOUNT_REF must be a non-PII identifier using only letters, digits, dot, underscore, colon, slash, or hyphen.');
}
}
if (config?.modes?.direct?.enabled && config.modes.direct.price <= 0n) {
errors.push('Direct payment mode is enabled but its price is not positive.');
}
@@ -272,6 +310,11 @@ class EnvironmentValidator {
warnings.push('Payout rules are enabled but PAYOUTS_ENABLED is off; the master switch suppresses all payout creation and dispatch.');
}
// A Such Software operated-product identifier is an exact public claim in every
// environment. Never let a development or preview process impersonate that identity
// while bypassing the host/network/economic contract.
errors.push(...validateOperatedProductProfile(env, config));
if (production) {
for (const key of BOOLEAN_ENV_KEYS) {
if (Object.prototype.hasOwnProperty.call(env, key)
+186
View File
@@ -0,0 +1,186 @@
'use strict';
/**
* Opt-in contracts for the two public products operated by Such Software.
*
* Independent MIT deployments do not set OPERATED_PRODUCT_PROFILE and are deliberately not
* constrained by these product decisions. Official production environments do set it, causing
* preflight and normal startup to reject any network, identity, or economic-scope drift.
*/
const OPERATED_PRODUCT_PROFILE_IDS = Object.freeze({
WOW_PRESTIGE: 'such-play-wow-prestige',
XMR_STAGENET: 'such-monerogue-stagenet'
});
const SOURCE_SOFTWARE = Object.freeze({
publisherName: 'Such Software',
contactUrl: 'mailto:apps@such.software',
contactLabel: 'apps@such.software',
license: 'MIT',
rightsNotice: 'Permission to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies is granted under the MIT License only if the copyright and permission notice is included in all copies or substantial portions.',
warrantyNotice: 'The software is provided “AS IS”, without warranty of any kind, express or implied, to the fullest extent stated in the MIT License.',
legalAdviceNotice: 'The software, documentation, examples, and disclosures are not legal advice, a licence, or a compliance approval.',
thirdPartyNotice: 'A third-party or self-hosted operator is solely responsible for its deployment, product design, legal compliance, funds, players, claims, and support. Such Software does not operate, supervise, endorse, or accept responsibility for third-party deployments.',
operatedBoundaryNotice: 'Such Software operates only play.wowne.ro and monerogue.app, and only within the product scopes stated for those services. It does not operate or endorse deployments made from this source by anyone else.'
});
const PROFILES = Object.freeze({
[OPERATED_PRODUCT_PROFILE_IDS.WOW_PRESTIGE]: Object.freeze({
id: OPERATED_PRODUCT_PROFILE_IDS.WOW_PRESTIGE,
hostname: 'play.wowne.ro',
publicUrl: 'https://play.wowne.ro',
operatorName: 'Such Software',
operatorContactUrl: SOURCE_SOFTWARE.contactUrl,
operatorContactLabel: SOURCE_SOFTWARE.contactLabel,
scopeNotice: 'Such Software operates play.wowne.ro only as Wownero mainnet free play and pay-for-credits leaderboard/prestige play. Credits are non-redeemable service entitlements. The service offers no prizes, winnings, cash-out, or payouts and is not offered or marketed as gambling; legal classification depends on applicable law.',
commerceSummary: 'This purchase grants non-redeemable service credits for leaderboard/prestige play only. play.wowne.ro offers no prize, payout, or cash-out and is not marketed as gambling.',
noRealValueNotice: null
}),
[OPERATED_PRODUCT_PROFILE_IDS.XMR_STAGENET]: Object.freeze({
id: OPERATED_PRODUCT_PROFILE_IDS.XMR_STAGENET,
hostname: 'monerogue.app',
publicUrl: 'https://monerogue.app',
operatorName: 'Such Software',
operatorContactUrl: SOURCE_SOFTWARE.contactUrl,
operatorContactLabel: SOURCE_SOFTWARE.contactLabel,
scopeNotice: 'Such Software operates monerogue.app only with Monero stagenet test coins. Its single-player 2×/3× outcomes are test gambling mechanics; no real-money or mainnet gambling is offered.',
commerceSummary: 'NO REAL VALUE — monerogue.app uses Monero stagenet test coins only. Single-player qualifying outcomes pay 2× or 3× in test coins; never send mainnet XMR.',
noRealValueNotice: 'NO REAL VALUE — Monero stagenet coins are test data, not money, deposits, redeemable prizes, or a promise of value. Never send mainnet XMR to this service.'
})
});
const TRUE_VALUES = new Set(['true', '1', 'yes', 'on']);
const FALSE_VALUES = new Set(['false', '0', 'no', 'off']);
function isExplicitTrue(value) {
return TRUE_VALUES.has(String(value ?? '').trim().toLowerCase());
}
function isExplicitFalse(value) {
return FALSE_VALUES.has(String(value ?? '').trim().toLowerCase());
}
function selectedProfileId(env = process.env) {
return String(env.OPERATED_PRODUCT_PROFILE || '').trim();
}
function getOperatedProductProfile(env = process.env) {
return PROFILES[selectedProfileId(env)] || null;
}
function isExactPublicRoot(value, expected) {
try {
const actual = new URL(String(value || ''));
const target = new URL(expected);
return actual.protocol === 'https:'
&& actual.username === ''
&& actual.password === ''
&& actual.origin === target.origin
&& (actual.pathname === '' || actual.pathname === '/')
&& actual.search === ''
&& actual.hash === '';
} catch (_) {
return false;
}
}
function exactMultiplier(value, expected) {
return String(value ?? '').trim() !== '' && Number(value) === expected;
}
function hasOutOfScopeProduct(config) {
const standaloneProducts = config?.products?.cosmetic || [];
const creditPackages = config?.modes?.credits?.packages || [];
// These two operated products sell only the top-level credits/bonus declared by a credit
// package. Reject the entire extensible grants object, including unknown future keys, so a
// new entitlement cannot silently widen the public product contract.
return standaloneProducts.length > 0
|| creditPackages.some(product => product
&& Object.prototype.hasOwnProperty.call(product, 'grants'));
}
function validateOperatedProductProfile(env = process.env, config = {}) {
const id = selectedProfileId(env);
if (!id) return [];
const profile = PROFILES[id];
if (!profile) {
return [`OPERATED_PRODUCT_PROFILE=${id} is unknown. Remove it for an independent MIT deployment or use a reviewed Such Software profile.`];
}
const errors = [];
const requireContract = (condition, requirement) => {
if (!condition) errors.push(`OPERATED_PRODUCT_PROFILE=${id} requires ${requirement}.`);
};
const cryptoType = String(env.CRYPTO_TYPE || config?.currency?.symbol || '').trim().toUpperCase();
const network = String(env.MONERO_NETWORK || '').trim().toLowerCase();
requireContract(isExactPublicRoot(env.HOSTED_BY, profile.publicUrl), `HOSTED_BY=${profile.publicUrl}`);
requireContract(String(env.OPERATOR_NAME || '').trim() === profile.operatorName,
`OPERATOR_NAME=${profile.operatorName}`);
requireContract(String(env.OPERATOR_CONTACT_URL || '').trim() === profile.operatorContactUrl,
`OPERATOR_CONTACT_URL=${profile.operatorContactUrl}`);
requireContract(String(env.OPERATOR_CONTACT_LABEL || '').trim() === profile.operatorContactLabel,
`OPERATOR_CONTACT_LABEL=${profile.operatorContactLabel}`);
requireContract(isExplicitTrue(env.PAYMENTS_ENABLED) && config?.paymentsEnabled === true,
'PAYMENTS_ENABLED=true');
requireContract(isExplicitTrue(env.PAID_ACKNOWLEDGEMENT_REQUIRED),
'PAID_ACKNOWLEDGEMENT_REQUIRED=true');
requireContract(isExplicitTrue(env.FREE_PLAY_ENABLED), 'FREE_PLAY_ENABLED=true');
requireContract(isExplicitFalse(env.MATCH_CRYPTO_RACE_ENABLED), 'MATCH_CRYPTO_RACE_ENABLED=false');
requireContract(isExplicitFalse(env.MATCH_PAYOUTS_ENABLED), 'MATCH_PAYOUTS_ENABLED=false');
requireContract(!hasOutOfScopeProduct(config),
'no standalone products or bundled entitlement grants; credit packages may grant only their top-level credits and bonus');
if (id === OPERATED_PRODUCT_PROFILE_IDS.WOW_PRESTIGE) {
requireContract(cryptoType === 'WOW', 'CRYPTO_TYPE=WOW');
requireContract(network === 'mainnet', 'MONERO_NETWORK=mainnet');
requireContract(String(env.PAYMENT_MODES || '').trim().toLowerCase() === 'credits',
'PAYMENT_MODES=credits');
requireContract(isExplicitFalse(env.DIRECT_PAYMENT_ENABLED)
&& config?.modes?.direct?.enabled === false, 'DIRECT_PAYMENT_ENABLED=false');
requireContract(isExplicitTrue(env.CREDITS_ENABLED)
&& config?.modes?.credits?.enabled === true, 'CREDITS_ENABLED=true');
requireContract(isExplicitFalse(env.PAYOUTS_ENABLED)
&& config?.payouts?.enabled === false, 'PAYOUTS_ENABLED=false');
requireContract(isExplicitFalse(env.DIRECT_PAYOUTS_ENABLED)
&& config?.payouts?.rules?.direct?.enabled === false, 'DIRECT_PAYOUTS_ENABLED=false');
requireContract(isExplicitFalse(env.CREDITS_PAYOUTS_ENABLED)
&& config?.payouts?.rules?.credits?.enabled === false, 'CREDITS_PAYOUTS_ENABLED=false');
requireContract(isExplicitFalse(env.ALLOW_MAINNET_PAYOUTS), 'ALLOW_MAINNET_PAYOUTS=false');
}
if (id === OPERATED_PRODUCT_PROFILE_IDS.XMR_STAGENET) {
requireContract(cryptoType === 'XMR', 'CRYPTO_TYPE=XMR');
requireContract(network === 'stagenet', 'MONERO_NETWORK=stagenet');
requireContract(String(env.PAYMENT_MODES || '').split(',').map(value => value.trim().toLowerCase()).join(',') === 'direct,credits',
'PAYMENT_MODES=direct,credits');
requireContract(isExplicitTrue(env.DIRECT_PAYMENT_ENABLED)
&& config?.modes?.direct?.enabled === true, 'DIRECT_PAYMENT_ENABLED=true');
requireContract(isExplicitTrue(env.CREDITS_ENABLED)
&& config?.modes?.credits?.enabled === true, 'CREDITS_ENABLED=true');
requireContract(isExplicitTrue(env.PAYOUTS_ENABLED)
&& config?.payouts?.enabled === true, 'PAYOUTS_ENABLED=true');
requireContract(isExplicitTrue(env.DIRECT_PAYOUTS_ENABLED)
&& config?.payouts?.rules?.direct?.enabled === true, 'DIRECT_PAYOUTS_ENABLED=true');
requireContract(isExplicitTrue(env.CREDITS_PAYOUTS_ENABLED)
&& config?.payouts?.rules?.credits?.enabled === true, 'CREDITS_PAYOUTS_ENABLED=true');
requireContract(exactMultiplier(env.DIRECT_PAYOUT_ESCAPE, 2), 'DIRECT_PAYOUT_ESCAPE=2');
requireContract(exactMultiplier(env.DIRECT_PAYOUT_TREASURE, 3), 'DIRECT_PAYOUT_TREASURE=3');
requireContract(exactMultiplier(env.CREDITS_PAYOUT_ESCAPE, 2), 'CREDITS_PAYOUT_ESCAPE=2');
requireContract(exactMultiplier(env.CREDITS_PAYOUT_TREASURE, 3), 'CREDITS_PAYOUT_TREASURE=3');
requireContract(isExplicitFalse(env.ALLOW_MAINNET_PAYOUTS), 'ALLOW_MAINNET_PAYOUTS=false');
}
return errors;
}
module.exports = {
OPERATED_PRODUCT_PROFILE_IDS,
SOURCE_SOFTWARE,
getOperatedProductProfile,
selectedProfileId,
validateOperatedProductProfile
};