diff --git a/website/control-panel/public/cp-v2/cp-v2-auth.mjs b/website/control-panel/public/cp-v2/cp-v2-auth.mjs index 13fe1a38..e255bca7 100644 --- a/website/control-panel/public/cp-v2/cp-v2-auth.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-auth.mjs @@ -18,12 +18,12 @@ export async function startCPAuthentication(onReady,{fetcher=fetch,locationTarge function showSignIn(){ host.replaceChildren();const art=el('img');art.src='https://www.dunerealms.com/assets/nav-account-v2.webp';art.alt='';art.width=art.height=96;host.append(art,el('p','YOUR PLACE IN THE IMPERIAL LEDGER','cp-v2-auth-eyebrow'),el('h1','Citizen Passport'),el('p','Sign in to your DuneRealms account.')); const tabs=el('div',undefined,'cp-v2-company-actions'),login=el('button','Sign in'),register=el('button','Create account');login.type=register.type='button';tabs.append(login,register); - const form=el('form'),name=el('input'),password=el('input');name.name='username';name.autocomplete='username';name.required=true;name.minLength=3;name.maxLength=32;name.pattern='[A-Za-z0-9_]{3,32}';password.name='password';password.type='password';password.autocomplete='current-password';password.required=true;password.minLength=1;password.maxLength=256; + const form=el('form'),name=el('input'),password=el('input');name.name='username';name.autocomplete='username';name.required=true;name.minLength=3;name.maxLength=32;name.pattern='[A-Za-z0-9_]{3,32}';password.name='password';password.type='password';password.autocomplete='current-password';password.required=true; const field=(label,input)=>{const node=el('label',label);node.append(input);return node;};form.append(field('DuneRealms name',name),field('Password',password)); const age=el('select');age.name='ageBand';for(const [value,label]of [['','Choose your age category'],['under15','Under 15'],['15to17','15–17'],['18plus','18 or older']]){const option=el('option',label);option.value=value;age.append(option);}const ageField=field('Age category',age);ageField.hidden=true;age.disabled=true; const bio=el('textarea');bio.name='bio';bio.minLength=10;bio.maxLength=1000;bio.rows=4;const bioField=field('Biography · required · 10–1,000 characters',bio); const send=el('button','Sign in');send.type='submit';const feedback=el('p');feedback.setAttribute('role','status');form.append(ageField,bioField,send,feedback);host.append(tabs,form);let mode='login'; - const select=value=>{mode=value;ageField.hidden=age.disabled=bioField.hidden=bio.disabled=value!=='register';age.required=bio.required=value==='register';password.autocomplete=value==='register'?'new-password':'current-password';password.minLength=value==='register'?12:1;send.textContent=value==='register'?'Create account':'Sign in';login.setAttribute('aria-pressed',String(value==='login'));register.setAttribute('aria-pressed',String(value==='register'));feedback.textContent='';};login.onclick=()=>select('login');register.onclick=()=>select('register');select('login'); + const select=value=>{mode=value;ageField.hidden=age.disabled=bioField.hidden=bio.disabled=value!=='register';age.required=bio.required=value==='register';password.autocomplete=value==='register'?'new-password':'current-password';send.textContent=value==='register'?'Create account':'Sign in';login.setAttribute('aria-pressed',String(value==='login'));register.setAttribute('aria-pressed',String(value==='register'));feedback.textContent='';};login.onclick=()=>select('login');register.onclick=()=>select('register');select('login'); form.onsubmit=async event=>{event.preventDefault();if(send.disabled)return;if(mode==='register'&&bio.value.trim().length<10){feedback.textContent='Write a biography of at least 10 characters.';bio.focus();return;}send.disabled=true;feedback.textContent='Opening your passport…';try{await request('auth/'+mode,{username:name.value.trim(),password:password.value,...(mode==='register'?{ageBand:age.value,bio:bio.value.trim()}:{})});password.value='';locationTarget.reload();}catch(error){password.value='';feedback.textContent=error.message;send.disabled=false;password.focus();}}; } function showOnboarding(){ diff --git a/website/control-panel/public/cp-v2/cp-v2-security.mjs b/website/control-panel/public/cp-v2/cp-v2-security.mjs index 2b4000de..3fd1af91 100644 --- a/website/control-panel/public/cp-v2/cp-v2-security.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-security.mjs @@ -2,7 +2,7 @@ import {createCPV2Page,element as el} from './cp-v2-page-template.mjs'; import {createUserAPI} from './cp-v2-user-api.mjs'; export function passwordPayload(currentPassword,newPassword,confirmed){ - if(confirmed!==true||typeof currentPassword!=='string'||!currentPassword||currentPassword.length>256||typeof newPassword!=='string'||newPassword.length<12||newPassword.length>256)throw Error('Confirm the change and enter your current password and a new password of 12–256 characters.'); + if(confirmed!==true||typeof currentPassword!=='string'||!currentPassword||typeof newPassword!=='string'||!newPassword)throw Error('Confirm the change and enter your current password and a new password.'); return {currentPassword,newPassword}; } export function contactPayload(action,{email='',code='',confirmed=false}={}){ @@ -19,7 +19,7 @@ export function mountSecurity(host,{fetcher=fetch}={}){ const passwordForm=el('form'),passwordFields=el('fieldset');passwordFields.disabled=true; passwordBox.append(el('h4','Website password'),el('p','Changing your password signs out your other website sessions. Your mailbox password remains separate.')); function input(parent,title,type='text'){const label=el('label'),caption=el('span',title),field=el('input');field.type=type;if(type==='checkbox'){label.className='security-check';label.append(field,caption);}else label.append(caption,field);parent.append(label);return field;} - const current=input(passwordFields,'Current website password','password'),fresh=input(passwordFields,'New password · at least 12 characters','password');current.autocomplete='current-password';fresh.autocomplete='new-password';current.required=fresh.required=true;current.maxLength=fresh.maxLength=256;fresh.minLength=12; + const current=input(passwordFields,'Current website password','password'),fresh=input(passwordFields,'New password','password');current.autocomplete='current-password';fresh.autocomplete='new-password';current.required=fresh.required=true; const passwordConsent=input(passwordFields,'I confirm changing my website password.','checkbox');passwordConsent.required=true; const passwordSave=el('button','Change password & sign out other sessions');passwordSave.type='submit';const passwordStatus=el('p');passwordStatus.setAttribute('role','status');passwordFields.append(passwordSave);passwordForm.append(passwordFields);passwordBox.append(passwordForm,passwordStatus); const mailStatus=el('p','Opening your notification settings…');mailStatus.setAttribute('role','status');const mailBody=el('div'),reload=el('button','Reload security settings');reload.type='button'; diff --git a/website/docs/PASSWORD-POLICY-OWNER-20261129.md b/website/docs/PASSWORD-POLICY-OWNER-20261129.md new file mode 100644 index 00000000..d7d8fd7d --- /dev/null +++ b/website/docs/PASSWORD-POLICY-OWNER-20261129.md @@ -0,0 +1,7 @@ +# Owner password policy — 29 November 2026 + +Owner explicitly requested removal of website password restrictions after continued sign-in trouble. Supersedes the registration/change minimum retained by the previous sign-in fix. + +Website sign-in, registration and password change now require a supplied non-empty password, without a password-specific minimum/maximum length or composition rule. Both public and CP forms match the API. Current-password verification, hashing, origin checks, rate limits, cookie security, roles and account records remain unchanged. Mailbox/provider credentials and separate bank-payment secrets are outside this website sign-in change. + +Validation: 13 focused tests passed, including one-character and 300-character registration/change/login, invalid credentials, existing nine-character login on both origins, and actual form mode switching. No production credentials or accounts modified by tests. Publication evidence follows the canonical web build, not an ad hoc live patch. diff --git a/website/node/auth.mjs b/website/node/auth.mjs index db75ab46..3560dd45 100644 --- a/website/node/auth.mjs +++ b/website/node/auth.mjs @@ -24,7 +24,7 @@ export function createAuth(db,origin,{trackFirstLogin=false,onAccountReady=async const user=await identity(request,db);if(!user)return json({message:'Sign in first.'},401); if(!allowed('password:'+user.id,5))return json({message:'Too many attempts. Please try later.'},429); let data;try{data=await request.json();}catch{return json({message:'Invalid request.'},400);} - if(typeof data.currentPassword!=='string'||data.currentPassword.length>256||typeof data.newPassword!=='string'||data.newPassword.length<12||data.newPassword.length>256)return json({message:'Use a new password of 12–256 characters.'},400); + if(typeof data.currentPassword!=='string'||!data.currentPassword||typeof data.newPassword!=='string'||!data.newPassword)return json({message:'Enter your current password and a new password.'},400); const row=await db.prepare('SELECT * FROM site_accounts WHERE id=?').bind(user.id).first(); const actual=await scrypt(data.currentPassword,row.password_salt,64); if(!timingSafeEqual(actual,Buffer.from(row.password_hash,'hex')))return json({message:'Incorrect current password.'},403); @@ -38,8 +38,7 @@ export function createAuth(db,origin,{trackFirstLogin=false,onAccountReady=async let data;try{data=await request.json();}catch{return json({message:'Send valid JSON.'},400);} const username=typeof data?.username==='string'?data.username.trim().toLowerCase():''; const password=data?.password; - const minimumPasswordLength=path==='/api/auth/register'?12:1; - if(!/^[a-z0-9_]{3,32}$/.test(username)||typeof password!=='string'||password.length256)return json({message:path==='/api/auth/register'?'Use a username of 3–32 letters, numbers or underscores and a password of 12–256 characters.':'Enter your existing password and a username of 3–32 letters, numbers or underscores.'},400); + if(!/^[a-z0-9_]{3,32}$/.test(username)||typeof password!=='string'||!password.length)return json({message:path==='/api/auth/register'?'Use a username of 3–32 letters, numbers or underscores and a password.':'Enter your existing password and a username of 3–32 letters, numbers or underscores.'},400); if(!allowed(username)||!allowed('global',120,60000))return json({message:'Too many attempts. Please try again later.'},429); if(path==='/api/auth/register'){ if(!['under15','15to17','18plus'].includes(data?.ageBand)) diff --git a/website/node/public/login.html b/website/node/public/login.html index 1c40835e..72e89588 100644 --- a/website/node/public/login.html +++ b/website/node/public/login.html @@ -1 +1 @@ -Sign in — dunerealms.com
JAVA + BEDROCK · THE CARAVAN ENDURESSupportMy account

Welcome back

Sign in to your DuneRealms account and continue your journey.

YOUR PLACE IN THE CONCORD

Welcome,
traveller.

Sign in to join discussions, save your player profile and contact staff privately.

+Sign in — dunerealms.com
JAVA + BEDROCK · THE CARAVAN ENDURESSupportMy account

Welcome back

Sign in to your DuneRealms account and continue your journey.

YOUR PLACE IN THE CONCORD

Welcome,
traveller.

Sign in to join discussions, save your player profile and contact staff privately.

diff --git a/website/node/public/login.js b/website/node/public/login.js index 7a3e3fbb..c1979fc1 100644 --- a/website/node/public/login.js +++ b/website/node/public/login.js @@ -5,7 +5,7 @@ ageField.textContent='Age category';age.name='ageBand';for(const [value,label]of form.insertBefore(ageField,document.querySelector('#account-note'));form.insertBefore(bioField,document.querySelector('#account-note')); function registrationFields(){const registering=mode==='register';bioField.hidden=ageField.hidden=bio.disabled=age.disabled=!registering;bio.required=age.required=registering;bio.setCustomValidity('');} bio.addEventListener('input',()=>bio.setCustomValidity(mode==='register'&&bio.value.trim().length<10?'Write a biography of at least 10 characters.':''));registrationFields(); -function change(next){mode=next;for(const type of ['login','register'])document.querySelector('#'+type+'-tab').setAttribute('aria-pressed',String(next===type));form.elements.password.autocomplete=mode==='register'?'new-password':'current-password';form.elements.password.minLength=mode==='register'?12:1;form.elements.password.placeholder=mode==='register'?'At least 12 characters':'Your existing password';submit.textContent=mode==='register'?'Create account →':'Sign in →';document.querySelector('#account-note').textContent=mode==='register'?'Choose 3–32 letters, numbers or underscores, and a password of at least 12 characters.':'Use your DuneRealms website account.';status.textContent='';} +function change(next){mode=next;for(const type of ['login','register'])document.querySelector('#'+type+'-tab').setAttribute('aria-pressed',String(next===type));form.elements.password.autocomplete=mode==='register'?'new-password':'current-password';form.elements.password.placeholder=mode==='register'?'Choose a password':'Your existing password';submit.textContent=mode==='register'?'Create account →':'Sign in →';document.querySelector('#account-note').textContent=mode==='register'?'Choose 3–32 letters, numbers or underscores, and a password.':'Use your DuneRealms website account.';status.textContent='';} for(const type of ['login','register'])document.querySelector('#'+type+'-tab').addEventListener('click',()=>{change(type);registrationFields();}); function destination(){const value=new URLSearchParams(location.search).get('return_to');return value&&value.startsWith('/')&&!value.startsWith('//')&&!/[\\\r\n]/.test(value)?value:'/portal.html';} form.addEventListener('submit',async event=>{event.preventDefault();submit.disabled=true;status.textContent='Please wait…';try{const response=await fetch('/api/auth/'+mode,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(Object.fromEntries(new FormData(form)))});const result=await response.json();if(!response.ok)throw Error(result.message||'Sign-in failed.');location.assign(destination());}catch(error){status.textContent=error.message;}finally{submit.disabled=false;}}); diff --git a/website/tests/cp-v2-user-pages.test.mjs b/website/tests/cp-v2-user-pages.test.mjs index 0fbc03a2..8915bf59 100644 --- a/website/tests/cp-v2-user-pages.test.mjs +++ b/website/tests/cp-v2-user-pages.test.mjs @@ -23,8 +23,9 @@ test('profile edits match the existing backend social contract and reject spoofe for(const birthday of ['2000-02-30','2999-01-01'])assert.throws(()=>profilePayload({...input,birthday})); }); test('website password form preserves current-password verification and explicit consent',()=>{ + assert.deepEqual(passwordPayload('current','a',true),{currentPassword:'current',newPassword:'a'}); assert.deepEqual(passwordPayload('current value','new password of adequate length',true),{currentPassword:'current value',newPassword:'new password of adequate length'}); - for(const values of [['current','short',true],['','long enough password',true],['current','long enough password',false]])assert.throws(()=>passwordPayload(...values)); + for(const values of [['','long enough password',true],['current','long enough password',false]])assert.throws(()=>passwordPayload(...values)); }); test('notification email uses the real request/confirm/remove/sync contract',()=>{ const payload=contactPayload('request',{email:'citizen@example.com',confirmed:true});assert.equal(normalizeContactEmail(payload.email),payload.email);assert.equal(payload.confirmed,true); diff --git a/website/tests/existing-password-forms.test.mjs b/website/tests/existing-password-forms.test.mjs index 8ef8be6d..690e758f 100644 --- a/website/tests/existing-password-forms.test.mjs +++ b/website/tests/existing-password-forms.test.mjs @@ -11,7 +11,7 @@ function node(tag='div',text=''){ setCustomValidity(){},focus(){}}; } -test('Citizen Passport switches the password constraint by mode and submits an existing nine-character password',async()=>{ +test('Citizen Passport has no password length constraints in either mode and submits an existing nine-character password',async()=>{ const nodes=[],surfaces=new Map(),writes=[];let reloads=0; const el=(tag,text)=>{const n=node(tag,text);nodes.push(n);return n;}; const document={body:node(),querySelector(selector){if(selector==='.command-banner')return null;if(!surfaces.has(selector))surfaces.set(selector,node());return surfaces.get(selector);}}; @@ -24,21 +24,21 @@ test('Citizen Passport switches the password constraint by mode and submits an e }}); const password=nodes.find(n=>n.name==='password'),name=nodes.find(n=>n.name==='username'),form=nodes.find(n=>n.tag==='form'); const login=nodes.find(n=>n.tag==='button'&&n.textContent==='Sign in'),register=nodes.find(n=>n.tag==='button'&&n.textContent==='Create account'); - assert.equal(password.minLength,1);assert.equal(password.maxLength,256);assert.equal(password.autocomplete,'current-password'); - register.onclick();assert.equal(password.minLength,12);assert.equal(password.autocomplete,'new-password'); - login.onclick();assert.equal(password.minLength,1);assert.equal(password.autocomplete,'current-password'); + assert.equal(password.minLength,undefined);assert.equal(password.maxLength,undefined);assert.equal(password.autocomplete,'current-password'); + register.onclick();assert.equal(password.minLength,undefined);assert.equal(password.autocomplete,'new-password'); + login.onclick();assert.equal(password.minLength,undefined);assert.equal(password.autocomplete,'current-password'); name.value='legacy_test';password.value='oldpass12';await form.onsubmit({preventDefault(){}}); assert.deepEqual(writes,[{path:'/api/auth/login',data:{username:'legacy_test',password:'oldpass12'}}]);assert.equal(reloads,1); }); -test('public sign-in starts with an existing-password constraint and retains the registration minimum',async()=>{ +test('public sign-in starts with an existing-password constraint and has no registration length constraint',async()=>{ const html=readFileSync(new URL('../node/public/login.html',import.meta.url),'utf8'); - assert.match(html,/autocomplete="current-password" required minlength="1" maxlength="256"/); - const form=node('form');form.elements={password:{minLength:1,maxLength:256}}; + assert.match(html,/autocomplete="current-password" required/); + const form=node('form');form.elements={password:{}}; const nodes=new Map([['#account-form',form]]); const document={createElement:tag=>node(tag),querySelector(selector){if(!nodes.has(selector))nodes.set(selector,node());return nodes.get(selector);}}; const source=readFileSync(new URL('../node/public/login.js',import.meta.url),'utf8'); vm.runInNewContext(source,{document,URLSearchParams,location:{search:''},fetch:async()=>({json:async()=>({authenticated:false})})}); - nodes.get('#register-tab').events.click();assert.equal(form.elements.password.minLength,12);assert.equal(form.elements.password.autocomplete,'new-password'); - nodes.get('#login-tab').events.click();assert.equal(form.elements.password.minLength,1);assert.equal(form.elements.password.autocomplete,'current-password'); + nodes.get('#register-tab').events.click();assert.equal(form.elements.password.minLength,undefined);assert.equal(form.elements.password.autocomplete,'new-password'); + nodes.get('#login-tab').events.click();assert.equal(form.elements.password.minLength,undefined);assert.equal(form.elements.password.autocomplete,'current-password'); }); diff --git a/website/tests/node-host.test.mjs b/website/tests/node-host.test.mjs index 0f6524dc..14a86753 100644 --- a/website/tests/node-host.test.mjs +++ b/website/tests/node-host.test.mjs @@ -38,7 +38,7 @@ test('MySQL profile upserts retain bound values',()=>{ assert.equal(mysqlSql('INSERT INTO player_profiles(user_id) VALUES(?) ON CONFLICT(user_id) DO UPDATE SET display_name=excluded.display_name'),'INSERT INTO player_profiles(user_id) VALUES(?) ON DUPLICATE KEY UPDATE display_name=VALUES(display_name)'); }); -test('existing nine-character passwords authenticate on both hosts without weakening new-password rules',async()=>{ +test('existing nine-character passwords authenticate on both hosts without changing stored credentials',async()=>{ const db=new LocalD1(schema+`CREATE TABLE cp_ranks(rank_key TEXT PRIMARY KEY,label TEXT,rank_level INTEGER,kind TEXT,permissions_json TEXT,version INTEGER);`); try{ const app=createApplication(db),account={username:'legacy_test',password:'A long registration password',ageBand:'18plus',bio:'An existing traveller of the desert.'}; @@ -53,12 +53,26 @@ test('existing nine-character passwords authenticate on both hosts without weake const cookie=signedIn.headers.get('set-cookie').split(';')[0];assert.match(cookie,/^__Host-dune_session=/); const session=await auth(new Request(host+'/api/auth/session',{headers:{Cookie:cookie}}));assert.equal((await session.json()).authenticated,true); assert.equal((await post('/api/auth/login',{username:account.username,password:'wrongpass'})).status,401); - for(const password of ['', 'x'.repeat(257)])assert.equal((await post('/api/auth/login',{username:account.username,password})).status,400); - assert.equal((await post('/api/auth/register',{...account,username:'new_citizen',password:existing})).status,400); - assert.equal((await post('/api/auth/password',{currentPassword:existing,newPassword:'shortpass'},cookie)).status,400); + assert.equal((await post('/api/auth/login',{username:account.username,password:''})).status,400); + assert.equal((await post('/api/auth/login',{username:account.username,password:'x'.repeat(257)})).status,401); } const unchanged=await db.prepare('SELECT * FROM site_accounts WHERE id=?').bind(row.id).first(); assert.equal(unchanged.password_hash,hash);assert.equal(unchanged.password_salt,row.password_salt);assert.equal(unchanged.role,row.role); assert.equal((await db.prepare('SELECT COUNT(*) AS n FROM site_accounts').first()).n,1); }finally{db.close();} }); + + +test('owner policy accepts short and long passwords for registration, login and changes',async()=>{ + const db=new LocalD1(schema+`CREATE TABLE cp_ranks(rank_key TEXT PRIMARY KEY,label TEXT,rank_level INTEGER,kind TEXT,permissions_json TEXT,version INTEGER);`);try{ + const auth=createAuth(db,origin),post=(path,data,cookie)=>auth(request(path,'POST',data,cookie?{Cookie:cookie}:{})); + for(const [i,password] of ['a','x'.repeat(300)].entries()){ + const username='policy_test_'+i; + const created=await post('/api/auth/register',{username,password,ageBand:'18plus',bio:'A test traveller in the desert.'});assert.equal(created.status,200); + const cookie=created.headers.get('set-cookie').split(';')[0]; + const changed=await post('/api/auth/password',{currentPassword:password,newPassword:password+'!'},cookie);assert.equal(changed.status,200); + assert.equal((await post('/api/auth/login',{username,password:password+'!'})).status,200); + assert.equal((await post('/api/auth/login',{username,password})).status,401); + } + }finally{db.close();} +});