Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump body-parser and express in /oidc-ui #888

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a35edc0
Updated pom version to 1.4.0-SNAPSHOT (#612)
ase-101 Mar 19, 2024
91d2143
[ES-879] Implemented functionality to dynamically display subheader t…
gk-XL7 Mar 21, 2024
5c74035
[FIXES] errorCode spelling mistake
zesu22 Mar 20, 2024
bb06f95
Merge pull request #618 from Infosys/bug/error_code
aranaravi Mar 26, 2024
a0acfe4
Replacing the (-) special character with empty in oidcTransactionId (…
aranaravi Mar 27, 2024
a3e7339
[ES-914] Fixed: OIDC-UI is not using the sbi.env config instead uses …
gk-XL7 Mar 27, 2024
bdfcd98
[ES-914] Fixed: OIDC-UI is not using the sbi.env config instead uses …
gk-XL7 Mar 27, 2024
4d10247
Merge pull request #624 from GurukiranP/ES914
aranaravi Mar 28, 2024
cf0a545
[ES-926] Fixed: In eSignet UI, Info in Username field is not clickabl…
gk-XL7 Mar 29, 2024
17a5e08
[ADDED] reset captcha after api failure
zesu22 Apr 2, 2024
82a17cb
Merge pull request #629 from Infosys/bug/ES-927
aranaravi Apr 2, 2024
6094bcf
[ES-911] added Knowledge basesd configurationd details into readme fi…
kaifk468 Apr 2, 2024
045f52d
MOSIP-32194 (#633)
ase-101 Apr 2, 2024
f0d06bf
ES-911 (#639)
ase-101 Apr 4, 2024
ceaa414
Updated the latest error codes (#644)
ase-101 Apr 4, 2024
1bd1687
[MODIFIED] resetting captchaToken with recaptcha wigdet
zesu22 Apr 5, 2024
6848343
Merge pull request #649 from Infosys/bug_release/ES-938
aranaravi Apr 5, 2024
34e2cab
Revert "[MODIFIED] resetting captchaToken with recaptcha wigdet" (#651)
ase-101 Apr 5, 2024
fc4bd0c
Added DB upgrade scripts (#652)
ase-101 Apr 5, 2024
a6f4a63
ES-911 (#654)
ase-101 Apr 5, 2024
3a633f7
Release changes (#655)
ckm007 Apr 5, 2024
97c5c6c
Updated Pom versions for release changes (#656)
ckm007 Apr 11, 2024
1a1ebbc
Merged changes from develop to release branch for 1.4.1 release (#671)
ase-101 May 2, 2024
a7ff43b
ES-1125
ase-101 May 2, 2024
9b90d00
Merge pull request #672 from ase-101/r1411
ckm007 May 2, 2024
04bd733
ES-937
ase-101 May 5, 2024
2853a03
Merge pull request #678 from ase-101/r1411
ckm007 May 6, 2024
aac776d
[INJIWEB-130] add logic to skip id-field check with challenge (#682)…
balaji-alluru May 7, 2024
905f5e9
[ES-1136]: Fixed - When transaction expired in login page incorrect e…
gk-XL7 May 15, 2024
19d6f0e
MOSIP-30868 Artifact id updated
Sohandey May 3, 2024
d6d90a0
[DSD-5071] Setu for apitest-esignet
VSIVAKALYAN May 5, 2024
0ecaa9a
[DSD-5071] Setup for apitest-esignet
VSIVAKALYAN May 6, 2024
7d16555
MOSIP-31134
ase-101 May 8, 2024
46e6346
ES-934
ase-101 May 13, 2024
6a5945c
MOSIP-31134
ase-101 May 13, 2024
494a913
ES-934
ase-101 May 20, 2024
8a2b417
[DSD-5071] Setup for apitest-esignet
VSIVAKALYAN May 9, 2024
b8a3afd
DSD-5071
Sohandey May 9, 2024
58aaf5a
DSD-5071
Sohandey May 10, 2024
2ce0555
MOSIP-33136
nandhu-kumar May 20, 2024
37be4c8
[MODIFIED] username type checking through new key (#675) (#710)
zesu22 May 21, 2024
23f2cbb
Merge pull request #709 from ase-101/release-141
ckm007 May 21, 2024
e946409
[MOSIP-33402] Updated chart-lint-publish.yml
Prafulrakhade Jun 4, 2024
3d36730
Merge pull request #746 from Prafulrakhade/release-1.4.x
ckm007 Jun 10, 2024
5069723
updated docker-compose with latest images (#760)
balaji-alluru Jun 10, 2024
d3927e5
[DSD-5447] Updated install.sh
Prafulrakhade Jun 11, 2024
8146a8c
Merge pull request #763 from Prafulrakhade/release-1.4.x
ckm007 Jun 11, 2024
bb37225
Release changes (#771)
ckm007 Jun 14, 2024
4a1055b
Update init_values.yaml
Prafulrakhade Jun 14, 2024
4c08c84
eSignet 1.4.1 release changes to master
ckm007 Jun 20, 2024
afcdf33
Bump body-parser and express in /oidc-ui
dependabot[bot] Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ public class Constants {
public static final String LINKED_SESSION_CACHE = "linked";
public static final String LINKED_CODE_CACHE = "linkedcode";
public static final String AUTH_CODE_GENERATED_CACHE = "authcodegenerated";
public static final String RATE_LIMIT_CACHE = "apiRateLimit";
public static final String BLOCKED_CACHE = "blocked";

public static final String ROOT_KEY = "ROOT";
public static final String OIDC_PARTNER_APP_ID = "OIDC_PARTNER";
Original file line number Diff line number Diff line change
@@ -84,4 +84,6 @@ public class ErrorConstants {
public static final String PROOF_HEADER_INVALID_ALG = "proof_header_invalid_alg";
public static final String PROOF_HEADER_INVALID_KEY = "proof_header_invalid_key";
public static final String PROOF_HEADER_AMBIGUOUS_KEY = "proof_header_ambiguous_key";
public static final String NO_ATTEMPTS_LEFT = "no_attempts_left";
public static final String INDIVIDUAL_ID_BLOCKED = "individual_id_blocked";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package io.mosip.esignet.core.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class ApiRateLimit implements Serializable {

ConcurrentHashMap<Integer, Integer> count = new ConcurrentHashMap<>();
ConcurrentHashMap<Integer, Long> lastInvocation = new ConcurrentHashMap<>();

public void increment(int apiCode) {
count.compute(apiCode, (k, v) -> (v == null) ? 1 : v + 1);
lastInvocation.compute(apiCode, (k, v) -> System.currentTimeMillis());
}
}
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ public class OIDCTransaction implements Serializable {
String state;

String individualId;
String individualIdHash;

String oauthDetailsHash;
ConsentAction consentAction;
Original file line number Diff line number Diff line change
@@ -2,12 +2,15 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.esignet.core.constants.ErrorConstants;
import io.mosip.esignet.core.dto.Error;
import io.mosip.esignet.core.dto.OIDCTransaction;
import io.mosip.esignet.core.dto.ApiRateLimit;
import io.mosip.esignet.core.dto.ResponseWrapper;
import io.mosip.esignet.core.exception.EsignetException;
import io.mosip.esignet.core.exception.InvalidTransactionException;
import io.mosip.esignet.core.util.IdentityProviderUtil;
import io.mosip.esignet.services.AuthorizationHelperService;
import io.mosip.esignet.services.CacheUtilService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +42,12 @@ public class HeaderValidationFilter extends OncePerRequestFilter {
@Value("#{${mosip.esignet.header-filter.paths-to-validate}}")
private List<String> pathsToValidate;

@Value("${mosip.esignet.send-otp.attempts:3}")
private int sendOtpAttempts;

@Value("${mosip.esignet.authenticate.attempts:3}")
private int authenticateAttempts;

@Autowired
private CacheUtilService cacheUtilService;

@@ -48,6 +57,7 @@ public class HeaderValidationFilter extends OncePerRequestFilter {
@Autowired
private MessageSource messageSource;


@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
final String path = request.getRequestURI();
@@ -59,15 +69,21 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
final String path = request.getRequestURI();

try {
log.info("Started to validate {} for oauth-details headers", path);
log.debug("Started to validate {} for oauth-details headers", path);
final String transactionId = request.getHeader(HEADER_OAUTH_DETAILS_KEY);
final String hashValue = request.getHeader(HEADER_OAUTH_DETAILS_HASH);
OIDCTransaction transaction = path.endsWith("auth-code") ? cacheUtilService.getAuthenticatedTransaction(transactionId) :
cacheUtilService.getPreAuthTransaction(transactionId);
if(transaction == null) {
throw new InvalidTransactionException();
}

//For the first attempt individualId will be null, hence blocked check is not required
if(transaction.getIndividualIdHash() != null && cacheUtilService.isIndividualIdBlocked(transaction.getIndividualIdHash()))
throw new EsignetException(ErrorConstants.INDIVIDUAL_ID_BLOCKED);

if(transaction.getOauthDetailsHash().equals(hashValue)) {
validateApiRateLimits(path, transactionId, transaction.getIndividualIdHash());
filterChain.doFilter(request, response);
return;
}
@@ -101,4 +117,38 @@ private String getMessage(String errorCode) {
}
return errorCode;
}

private void validateApiRateLimits(String path, String transactionId, String individualIdHash) {
int apiCode = path.endsWith("send-otp") ? 1 : path.endsWith("authenticate")? 2 : 3;

switch (apiCode) {
case 1:
ApiRateLimit sendOtpLimit = cacheUtilService.getApiRateLimitTransaction(transactionId);
checkCountLimit(1, sendOtpLimit, sendOtpAttempts, individualIdHash);
cacheUtilService.saveApiRateLimit(transactionId, sendOtpLimit);
break;
case 2:
ApiRateLimit authenticateLimit = cacheUtilService.getApiRateLimitTransaction(transactionId);
checkCountLimit(2, authenticateLimit, authenticateAttempts, individualIdHash);
cacheUtilService.saveApiRateLimit(transactionId, authenticateLimit);
break;
}
}

private void checkCountLimit(int apiCode, ApiRateLimit apiRateLimit, int attemptsLimit, String individualId) {
if(apiRateLimit == null) {
apiRateLimit = new ApiRateLimit();
}
apiRateLimit.increment(apiCode);
if(apiRateLimit.getCount().get(apiCode) > attemptsLimit) {
blockIndividualId(individualId);
throw new EsignetException(ErrorConstants.NO_ATTEMPTS_LEFT);
}
}

private void blockIndividualId(String individualIdHash) {
if(individualIdHash != null) {
cacheUtilService.blockIndividualId(individualIdHash);
}
}
}
Original file line number Diff line number Diff line change
@@ -145,6 +145,7 @@ public OtpResponse sendOtp(OtpRequest otpRequest) throws EsignetException {
if(transaction == null)
throw new InvalidTransactionException();

cacheUtilService.updateIndividualIdHashInPreAuthCache(otpRequest.getTransactionId(), otpRequest.getIndividualId());
SendOtpResult sendOtpResult = authorizationHelperService.delegateSendOtpRequest(otpRequest, transaction);
OtpResponse otpResponse = new OtpResponse();
otpResponse.setTransactionId(otpRequest.getTransactionId());
@@ -226,6 +227,7 @@ private OIDCTransaction authenticate(AuthRequest authRequest, boolean checkConse
if(transaction == null)
throw new InvalidTransactionException();

cacheUtilService.updateIndividualIdHashInPreAuthCache(authRequest.getTransactionId(), authRequest.getIndividualId());
//Validate provided challenge list auth-factors with resolved auth-factors for the transaction.
Set<List<AuthenticationFactor>> providedAuthFactors = authorizationHelperService.getProvidedAuthFactors(transaction,
authRequest.getChallengeList());
Original file line number Diff line number Diff line change
@@ -7,16 +7,21 @@

import io.mosip.esignet.core.dto.OIDCTransaction;
import io.mosip.esignet.core.dto.LinkTransactionMetadata;
import io.mosip.esignet.core.dto.ApiRateLimit;
import io.mosip.esignet.core.exception.DuplicateLinkCodeException;
import io.mosip.esignet.core.constants.Constants;
import io.mosip.esignet.core.util.IdentityProviderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import static io.mosip.esignet.core.util.IdentityProviderUtil.ALGO_SHA3_256;


@Slf4j
@Service
@@ -104,6 +109,25 @@ public OIDCTransaction updateTransactionAndEvictLinkCode(String transactionId, S
return oidcTransaction;
}

@CachePut(value = Constants.RATE_LIMIT_CACHE, key = "#transactionId")
public ApiRateLimit saveApiRateLimit(String transactionId, ApiRateLimit apiRateLimit) {
return apiRateLimit;
}

@Cacheable(value = Constants.BLOCKED_CACHE, key = "#individualIdHash")
public String blockIndividualId(String individualIdHash) {
return individualIdHash;
}

@Cacheable(value = Constants.PRE_AUTH_SESSION_CACHE, key = "#transactionId")
public OIDCTransaction updateIndividualIdHashInPreAuthCache(String transactionId, String individualId) {
OIDCTransaction oidcTransaction = cacheManager.getCache(Constants.PRE_AUTH_SESSION_CACHE).get(transactionId, OIDCTransaction.class);//NOSONAR getCache() will not be returning null here.
if(oidcTransaction != null) {
oidcTransaction.setIndividualIdHash(IdentityProviderUtil.generateB64EncodedHash(ALGO_SHA3_256, individualId));
}
return oidcTransaction;
}

//------------------------------------------------------------------------------------------------------------------

public OIDCTransaction getPreAuthTransaction(String transactionId) {
@@ -141,4 +165,13 @@ public OIDCTransaction getLinkedSessionTransaction(String linkTransactionId) {
public OIDCTransaction getLinkedAuthTransaction(String linkTransactionId) {
return cacheManager.getCache(Constants.LINKED_AUTH_CACHE).get(linkTransactionId, OIDCTransaction.class); //NOSONAR getCache() will not be returning null here.
}

public ApiRateLimit getApiRateLimitTransaction(String transactionId) {
return cacheManager.getCache(Constants.RATE_LIMIT_CACHE).get(transactionId, ApiRateLimit.class); //NOSONAR getCache() will not be returning null here.
}

public boolean isIndividualIdBlocked(String individualIdHash) {
String idHash = cacheManager.getCache(Constants.BLOCKED_CACHE).get(individualIdHash, String.class); //NOSONAR getCache() will not be returning null here.
return idHash != null;
}
}