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

Config http headers #37

Closed
wants to merge 22 commits into from
Closed

Config http headers #37

wants to merge 22 commits into from

Conversation

BettyB979
Copy link
Contributor

SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.securityMatcher("/**")
.csrf(csrfConfig -> csrfConfig.disable())

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
Comment on lines +47 to +49
return http
.securityMatcher("/**")
.csrf(AbstractHttpConfigurer::disable)

Check failure

Code scanning / CodeQL

Disabled Spring CSRF protection High

CSRF vulnerability due to protection being disabled.
@BettyB979 BettyB979 closed this Nov 15, 2023
@BettyB979 BettyB979 reopened this Nov 15, 2023
@BettyB979 BettyB979 marked this pull request as draft November 16, 2023 10:31
@BettyB979 BettyB979 marked this pull request as ready for review November 17, 2023 13:47
Copy link
Contributor

@davdarras davdarras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for tomorrow review to discuss tests (didn't check these ones)

@Bean
public UserProvider getUserProvider() {
return auth -> new User();
}

private String[] publicUrls(){
String[] str = new String[config.getPublicUrls().size()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot have directly public urls as array ?

return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toCollection(ArrayList::new));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toList() instead

authorizedRoles.addAll(applicationConfig.getRoleWebClient());

return roles.stream()
.map(role -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter can be used instead of returning null sometimes then filter on non null objects
.filter(role -> authorizedRoles.contains(role))
.map(SimpleGrantedAuthority::new)

.policy(ReferrerPolicyHeaderWriter.ReferrerPolicy.SAME_ORIGIN)
))
.anonymous(anonymousConfig -> anonymousConfig
.authorities("ROLE_ADMIN"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you use this role anywhere in the app ?

}

private String[] publicUrls() {
return new String[]{"/csrf", "/", "/webjars/**", "/swagger-resources/**", "/environnement", Constants.API_HEALTHCHECK, "/actuator/**",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe parameterize these urls in a conf file ? all these paths are used ?

@@ -99,5 +99,6 @@ private Constants() {
public static final String REVIEWER = "reviewer";

public static final String API_HEALTHCHECK = "/api/healthcheck";
public static final String ACTUATOR = "/actuator/**";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide this class into 2 and give them a more specific name ? one to define URL apis, another for roles


import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.Data;

@Entity
@Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaTa should not be used on entities: https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/

Here is not the best place to write this as there are only string properties, but it's best not to use @DaTa @EqualsAndHashCode @tostring on entities at all

import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.ToString;
import java.util.Date;

@Entity
@Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -35,14 +22,15 @@ public enum ContactEventType {
private Long id;
private Date eventDate;
@NonNull
@Enumerated(EnumType.STRING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enumerated variables are constant, so no lower case (CREATE, UPDATE, ...).

You should certainly use a converter instead: https://stackoverflow.com/questions/60500739/storing-enum-custom-values-with-jpa

import fr.insee.survey.datacollectionmanagement.metadata.service.PartitioningService;
import jakarta.ws.rs.NotFoundException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error when importing ?

Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 14 Code Smells

No Coverage information No Coverage information
3.2% 3.2% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@BettyB979 BettyB979 closed this Nov 23, 2023
@nicolasTurban nicolasTurban deleted the config_http_headers branch December 20, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants