You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original Identity Server 4 code base has several security bugs detected by CodeQL scanning violating this rule.
Description:
Many C# constructs enable code statements to be executed conditionally, for example, if statements and for statements. If the statements contain important authentication or login code, and user-controlled data determines whether or not the code is executed, an attacker may be able to bypass security systems.
if(button!="login"){if(context!=null){// if the user cancels, send a result back into IdentityServer as if they // denied the consent (even if this client does not require consent).// this will send back an access denied OIDC error response to the client.await_interaction.DenyAuthorizationAsync(context,AuthorizationError.AccessDenied);// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-nullif(context.IsNativeClient()){// The client is native, so this change in how to// return the response is for better UX for the end user.returnthis.LoadingPage("Redirect",model.ReturnUrl);}returnRedirect(model.ReturnUrl);}else{// since we don't have a valid context, then we just go back to the home pagereturnRedirect("~/");}}if(ModelState.IsValid){// validate username/password against in-memory storeif(_users.ValidateCredentials(model.Username,model.Password)){varuser=_users.FindByUsername(model.Username);await_events.RaiseAsync(newUserLoginSuccessEvent(user.Username,user.SubjectId,user.Username,clientId:context?.Client.ClientId));// only set explicit expiration here if user chooses "remember me". // otherwise we rely upon expiration configured in cookie middleware.AuthenticationPropertiesprops=null;if(AccountOptions.AllowRememberLogin&&model.RememberLogin){props=newAuthenticationProperties{IsPersistent=true,ExpiresUtc=DateTimeOffset.UtcNow.Add(AccountOptions.RememberMeLoginDuration)};};// issue authentication cookie with subject ID and usernamevarisuser=newIdentityServerUser(user.SubjectId){DisplayName=user.Username};awaitHttpContext.SignInAsync(isuser,props);if(context!=null){if(context.IsNativeClient()){// The client is native, so this change in how to// return the response is for better UX for the end user.returnthis.LoadingPage("Redirect",model.ReturnUrl);}// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-nullreturnRedirect(model.ReturnUrl);}// request for a local pageif(Url.IsLocalUrl(model.ReturnUrl)){returnRedirect(model.ReturnUrl);}elseif(string.IsNullOrEmpty(model.ReturnUrl)){returnRedirect("~/");}else{// user might have clicked on a malicious link - should be loggedthrownewException("invalid return URL");}}await_events.RaiseAsync(newUserLoginFailureEvent(model.Username,"invalid credentials",clientId:context?.Client.ClientId));ModelState.AddModelError(string.Empty,AccountOptions.InvalidCredentialsErrorMessage);}
Never decide whether to authenticate a user based on data that may be controlled by that user. If necessary, ensure that the data is validated extensively when it is input before any authentication checks are performed or authentication flows are performed.
Explicit form actions should be supplied for each user input and the code flow should not depend on the a user-injectable input value.
It is still possible to have a system that "remembers" users, thus not requiring the user to login on every interaction. For example, personalization settings can be applied without authentication because this is not sensitive information. However, users should be allowed to take sensitive actions only when they have been fully authenticated.
Example
This example shows two ways of deciding whether to authenticate a user. The first way shows a decision that is based on the value of a cookie. Cookies can be easily controlled by the user, and so this allows a user to become authenticated without providing valid credentials. The second, more secure way shows a decision that is based on looking up the user in a security database.
publicbooleandoLogin(HttpCookieadminCookie,Stringuser,Stringpassword){// BAD: login is executed only if the value of 'adminCookie' is 'false',// but 'adminCookie' is controlled by the userif(adminCookie.Value=="false")returnlogin(user,password);returntrue;}publicbooleandoLogin(HttpCookieadminCookie,Stringuser,Stringpassword){// GOOD: use server-side information based on the credentials to decide// whether user has privilegesboolisAdmin=queryDbForAdminStatus(user,password);if(!isAdmin)returnlogin(user,password);returntrue;}
This example shows explicit code flows based on the event fired.
User-controlled bypass of sensitive method
The original Identity Server 4 code base has several security bugs detected by CodeQL scanning violating this rule.
Description:
Many C# constructs enable code statements to be executed conditionally, for example, if statements and for statements. If the statements contain important authentication or login code, and user-controlled data determines whether or not the code is executed, an attacker may be able to bypass security systems.
Examples
Issues
Recommendation
Never decide whether to authenticate a user based on data that may be controlled by that user. If necessary, ensure that the data is validated extensively when it is input before any authentication checks are performed or authentication flows are performed.
Explicit form actions should be supplied for each user input and the code flow should not depend on the a user-injectable input value.
It is still possible to have a system that "remembers" users, thus not requiring the user to login on every interaction. For example, personalization settings can be applied without authentication because this is not sensitive information. However, users should be allowed to take sensitive actions only when they have been fully authenticated.
Example
This example shows two ways of deciding whether to authenticate a user. The first way shows a decision that is based on the value of a cookie. Cookies can be easily controlled by the user, and so this allows a user to become authenticated without providing valid credentials. The second, more secure way shows a decision that is based on looking up the user in a security database.
This example shows explicit code flows based on the event fired.
References
The text was updated successfully, but these errors were encountered: