From da680e287b18ce1d3d6091441affaf6e3db9ebe0 Mon Sep 17 00:00:00 2001 From: William Murphy Date: Thu, 1 Feb 2024 13:15:39 -0600 Subject: [PATCH 1/2] fix autosubmit username skipping form validation. Fix autogenerated username not checking length for validity --- src/auth/oauthClient.js | 2 ++ views/oidc-interstitial/oidc-interstitial.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/auth/oauthClient.js b/src/auth/oauthClient.js index 1180a72..a6426be 100644 --- a/src/auth/oauthClient.js +++ b/src/auth/oauthClient.js @@ -356,6 +356,8 @@ function interpolateUsernameTemplate (client, ssoData) { .replace(/\{(\w+)\}/g, (_, key) => ssoData[key] ?? '') // strip any characters not allowed in username .replace(/[^A-Za-z0-9-]/g, '') + // limit to max username length + .substring(0, 32) console.log( 'Generated username from template %s and data %j: %s', client.usernameTemplate, diff --git a/views/oidc-interstitial/oidc-interstitial.js b/views/oidc-interstitial/oidc-interstitial.js index 4f45ee5..916be94 100644 --- a/views/oidc-interstitial/oidc-interstitial.js +++ b/views/oidc-interstitial/oidc-interstitial.js @@ -91,7 +91,7 @@ function RegisterForm ({ domain, fetching, setFetching }) { }, [setFetching, setTakenMessage, setRegistrationError, setRegistrationSuccess]) useEffect(() => { // auto-submit form when page loads if username prefilled - if (proposedUsername) { + if (proposedUsername && formEl.reportValidity()) { formEl.current.dispatchEvent( new Event('submit', { bubbles: true, cancelable: true }) ) From 4ec4ac73770d9159d7432ed6b510bd7cebeeafa2 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Thu, 1 Feb 2024 14:44:17 -0600 Subject: [PATCH 2/2] unwrap ref and update form validation for browser changes --- views/components/HandleInput.js | 2 +- views/oidc-interstitial/oidc-interstitial.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/components/HandleInput.js b/views/components/HandleInput.js index 016f9a8..d33f691 100644 --- a/views/components/HandleInput.js +++ b/views/components/HandleInput.js @@ -26,7 +26,7 @@ export default class HandleInput extends React.Component { id='username' type='text' inputMode='email' name='username' placeholder='username' - required pattern='^[A-Za-z0-9-]{3,32}$' + required pattern='[A-Za-z0-9\-]{3,32}' autoCapitalize='off' autoCorrect='off' spellCheck='false' title='Letters, numbers, & dashes only, between 3 and 32 characters' value={this.state.username} diff --git a/views/oidc-interstitial/oidc-interstitial.js b/views/oidc-interstitial/oidc-interstitial.js index 916be94..a634465 100644 --- a/views/oidc-interstitial/oidc-interstitial.js +++ b/views/oidc-interstitial/oidc-interstitial.js @@ -91,7 +91,7 @@ function RegisterForm ({ domain, fetching, setFetching }) { }, [setFetching, setTakenMessage, setRegistrationError, setRegistrationSuccess]) useEffect(() => { // auto-submit form when page loads if username prefilled - if (proposedUsername && formEl.reportValidity()) { + if (proposedUsername && formEl.current.reportValidity()) { formEl.current.dispatchEvent( new Event('submit', { bubbles: true, cancelable: true }) )