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

g:form csrf protection adjustments #550

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
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
Expand Up @@ -22,6 +22,7 @@ import grails.gsp.TagLib
import groovy.transform.CompileStatic
import groovy.util.logging.Commons
import org.grails.plugins.web.GrailsTagDateHelper
import org.springframework.beans.BeansException

import java.text.DateFormat
import java.text.DateFormatSymbols
Expand Down Expand Up @@ -76,6 +77,10 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (applicationContext.containsBean('mvcConversionService')) {
conversionService = applicationContext.getBean('mvcConversionService', ConversionService)
}
configureCsrf()
}

void configureCsrf() {
try {
var filterChainProxy = applicationContext.getBean(
Class.forName("org.springframework.security.web.FilterChainProxy"))
Expand All @@ -85,7 +90,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
springSecurityCsrfTokenClass =
Class.forName("org.springframework.security.web.csrf.CsrfToken")
}
} catch (ClassNotFoundException ignore) {}
} catch (ClassNotFoundException | BeansException ignore) {}
Copy link

Choose a reason for hiding this comment

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

This works. My only question is you want to ignore all bean exceptions rather than just NoSuchBeanDefinitionException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkoehm because there could be a situation where you have no bean and also a situation where you have 2 beans the you should only have 1. this catches both of them. There could very well be a situation where somebody mistakenly has a duplicate registration. No need to fail because of that and both of those exception types extend BeansException.

}

/**
Expand Down
Loading