I recently took over a service at work that handles credit card encryption. It a Spring Boot 2.0 application and credit card info is passed in via a POST api.
Our security team was able to obtain credit card numbers using memory scraping attack, and I'm looking for ways to fix this.
Credit card number is stored as string in the request DTO. Here are relevant code
public ResponseEntity<ResponseDTO> saveCreditCard(@RequestBody @Validated CreditCardDTO creditCardDTO){
....
}
@Data
@NoArgsConstructor
public class CreditCardDTO {
@CreditCardNumber
private String ccNumber;
...
}
Is this the root cause of this security issue? Shouldn't the DTO be GCed once the request is completed? The application has a 2G heap and very low traffic, is it possible for Java to not trigger GC for weeks?
Also, what are my remedy options? I do want to keep validations like @CreditCardNumber
. And changing the API format is probably not acceptable.
IMO setting the DTO to null
or calling System.gc()
isn't guaranteed to work. Plus the GC pause could be an issue as well.