Fix signup validation and recaptcha handling#1483
Open
MerwinJoshwa wants to merge 1 commit intofossasia:developmentfrom
Open
Fix signup validation and recaptcha handling#1483MerwinJoshwa wants to merge 1 commit intofossasia:developmentfrom
MerwinJoshwa wants to merge 1 commit intofossasia:developmentfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts signup flow validation and reCAPTCHA handling to reject empty/whitespace inputs earlier while tightening reCAPTCHA checks, and makes minor style/robustness fixes in the signup service. Sequence diagram for updated signup validation and reCAPTCHA flowsequenceDiagram
actor User
participant FrontendApp
participant SignUpService
participant DAO
participant VerifyRecaptcha
User->>FrontendApp: submit signup(signup, password, g_recaptcha_response)
FrontendApp->>SignUpService: HTTP POST /signup
SignUpService->>SignUpService: trim signup, password
alt signup or password empty
SignUpService-->>FrontendApp: 422 signup or password empty
FrontendApp-->>User: show validation error
else inputs present
SignUpService->>SignUpService: validate email pattern
alt invalid email
SignUpService-->>FrontendApp: 422 invalid email
FrontendApp-->>User: show email error
else valid email
SignUpService->>DAO: getAuthentication(signup)
DAO-->>SignUpService: Authentication
alt user already exists
SignUpService-->>FrontendApp: 422 user already exists
FrontendApp-->>User: show user exists error
else new user
SignUpService->>DAO: getConfig users.captcha.signup
DAO-->>SignUpService: isSignUpCaptchaEnabled
alt captcha enabled
SignUpService->>SignUpService: read g-recaptcha-response
alt empty or missing
SignUpService-->>FrontendApp: 422 Please verify recaptcha
FrontendApp-->>User: show recaptcha required
else present
SignUpService->>VerifyRecaptcha: verify(g_recaptcha_response)
VerifyRecaptcha-->>SignUpService: boolean
alt verification failed
SignUpService-->>FrontendApp: 422 Please verify recaptcha
FrontendApp-->>User: show recaptcha error
else verification ok
SignUpService->>DAO: create user, store credentials
DAO-->>SignUpService: success
SignUpService-->>FrontendApp: 200 signup success
FrontendApp-->>User: show success
end
end
else captcha disabled
SignUpService->>DAO: create user, store credentials
DAO-->>SignUpService: success
SignUpService-->>FrontendApp: 200 signup success
FrontendApp-->>User: show success
end
end
end
end
Class diagram for SignUpService and related components after validation changesclassDiagram
class SignUpService {
+JSONObject getDefaultPermissions(UserRole baseUserRole)
+ServiceResponse serviceImpl(Query post, HttpServletResponse response, Authorization authorization)
-String getVerificationMailContent(String token, String userId) throws APIException
}
class Query {
+String get(String key, String defaultValue)
}
class Authorization {
+ClientIdentity getIdentity()
+void setUserRole(UserRole role)
}
class ClientIdentity {
+String getName()
+boolean isEmail()
}
class ClientCredential {
<<enumeration>> Type
+Type type
+String name
+ClientCredential(Type type, String name)
}
class Authentication {
+boolean exists()
}
class DAO {
+static String getConfig(String key, String defaultValue)
+static Authentication getAuthentication(ClientCredential credential)
}
class VerifyRecaptcha {
+static boolean verify(String gRecaptchaResponse)
}
class EmailHandler {
+static String EMAIL_PATTERN
}
class TimeoutMatcher {
+TimeoutMatcher(java.util.regex.Matcher matcher)
+boolean matches()
}
class UserRole {
<<enumeration>>
SUPERADMIN
ADMIN
OPERATOR
USER
}
class ServiceResponse
class JSONObject
class HttpServletResponse
class APIException
SignUpService --> Query : uses
SignUpService --> Authorization : uses
SignUpService --> ClientIdentity : uses
SignUpService --> ClientCredential : creates
SignUpService --> Authentication : uses
SignUpService --> DAO : uses
SignUpService --> VerifyRecaptcha : verifies
SignUpService --> EmailHandler : uses pattern
SignUpService --> TimeoutMatcher : uses
SignUpService --> ServiceResponse : returns
SignUpService --> JSONObject : builds permissions
SignUpService --> HttpServletResponse : writes response
SignUpService --> APIException : throws
Authorization --> UserRole : sets
ClientCredential --> ClientCredential.Type : has
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1476
Changes:
Screenshots for the change:
Summary by Sourcery
Improve signup validation robustness and reCAPTCHA enforcement in the signup API.
Bug Fixes:
Enhancements: