We use slf4j, and we're trying to use the html encoder in ESAPI. Initially, we were using version 2.1.0.1 of ESAPI. I asked about the slf4j integration on StackOverflow, and I was told that version 2.2.0.0 has direct support for slf4j. The problem is, except for the github issue mentioning this, I can't find any documentation that shows how to actually do this. From some implications in the issue thread, I imagine it might be setting the ESAPI.Logger to Slf4JLogFactory, but that's just a guess.What am I missing?
--
You received this message because you are subscribed to the Google Groups "ESAPI Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-u...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/cf1a9130-610a-4183-bfe8-9350d0b42ae0%40owasp.org.
David,I'm going to assume that:
- You already have SLF4J configured to work separately by your application, but just don't have it configured for ESAPI to use it.
- You already have ESAPI logging to log correctly in some other way (i.e., it's already logging with either java.util.logging or log4j 1.x).
In that case, I think that all you should need to do find the "ESAPI.Logger" property in your ESAPI.properties file and change it to:ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory
which is documented in ESAPI.properties file itself. (By the way, make sure you pull the ESAPI.properties file from GitHub from the 'configuration/esapi/ESAPI.properties' file and the test one from 'src/test/resources/esapi' which is prominently marked 'TEST VERS' at the top. Unfortunately, we haven't figured out how to get a zip file of that and other files under 'configuration/' directory uploaded to Maven Central even though we've tried many different ways to get that done._Otherwise, it should be used just like you normally use ESAPI logging just as you normally would if you were using it with JUL or log4j 1.x.@Jeremiah: Did I leave anything out?-kevin
On Sun, Oct 13, 2019 at 2:19 AM David Karr <davidmic...@gmail.com> wrote:
--We use slf4j, and we're trying to use the html encoder in ESAPI. Initially, we were using version 2.1.0.1 of ESAPI. I asked about the slf4j integration on StackOverflow, and I was told that version 2.2.0.0 has direct support for slf4j. The problem is, except for the github issue mentioning this, I can't find any documentation that shows how to actually do this. From some implications in the issue thread, I imagine it might be setting the ESAPI.Logger to Slf4JLogFactory, but that's just a guess.What am I missing?
You received this message because you are subscribed to the Google Groups "ESAPI Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-users+unsub...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/cf1a9130-610a-4183-bfe8-9350d0b42ae0%40owasp.org.
On Sunday, October 13, 2019 at 9:46:48 AM UTC-7, Kevin W. Wall wrote:David,I'm going to assume that:
- You already have SLF4J configured to work separately by your application, but just don't have it configured for ESAPI to use it.
Yes, we get Loggers from the slf4j LoggerFactory class. We have ESAPI available, but all we're doing with it so far is calling the encoders directly, like "ESAPI.encoder().encodeForHTML(...)".
- You already have ESAPI logging to log correctly in some other way (i.e., it's already logging with either java.util.logging or log4j 1.x).
I assume you're listing these as "either this one or that one", not both. I don't believe we have the latter.In that case, I think that all you should need to do find the "ESAPI.Logger" property in your ESAPI.properties file and change it to:ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactoryWe do have a ESAPI.properties file that sets a handful of ESAPI properties. I've added this line to that file.which is documented in ESAPI.properties file itself. (By the way, make sure you pull the ESAPI.properties file from GitHub from the 'configuration/esapi/ESAPI.properties' file and the test one from 'src/test/resources/esapi' which is prominently marked 'TEST VERS' at the top. Unfortunately, we haven't figured out how to get a zip file of that and other files under 'configuration/' directory uploaded to Maven Central even though we've tried many different ways to get that done._Otherwise, it should be used just like you normally use ESAPI logging just as you normally would if you were using it with JUL or log4j 1.x.@Jeremiah: Did I leave anything out?-kevinAfter I made that change, I executed a line likelog.debug("stuff {}", object)where I had deliberately set one of the properties of the object to have html text in it, and the result had the unmodified html text in it. I then instead executing a line likelog.debug( "stuff {}", ESAPI.encoder().encodeForHTML(object.toString())And the result had the html text properly encoded.I also set breakpoints in the ESAPI code, and the first execution never hit any of them. The latter did hit several. Note that our ESAPI.properties file hasEncoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodecWhich I would guess means that it should do the html encoding implicitly.So, either I'm misunderstanding and misinterpreting what this ESAPI integration is supposed to do, or I'm missing a step.
In order for the HTMLCodec to be applied, the property 'Logger.LogEncodingRequired' must also be set to true in ESAPI.properties.
Without that value, only newlines are replaced.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-u...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/cf1a9130-610a-4183-bfe8-9350d0b42ae0%40owasp.org.
--
Blog: http://off-the-wall-security.blogspot.com/ | Twitter: @KevinWWall
NSA: All your crypto bit are belong to us.
--
You received this message because you are subscribed to the Google Groups "ESAPI Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-u...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/0e25b64d-382c-0427-4e9b-793fa970868d%40gmail.com.
In order for the HTMLCodec to be applied, the property 'Logger.LogEncodingRequired' must also be set to true in ESAPI.properties.
Without that value, only newlines are replaced.
Reading back through this, I would like to offer a clarification.
The way the subject line reads and from the logging snippets
you've offered I get the impression you're using the SLF4J logging
API in your application and want to have ESAPI receive the log
message and escape it?
The behavior is actually inverse from that. Your application
must use the ESAPI Logging API, and the ESAPI Logger can delegate
to a configured SLF4J configuration.
The escaping happens before SLF4J, not after.
Please let me know if that changes the issue at all. I will do
my best to continue debugging this evening.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-u...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/e2b32ca3-aafd-4125-978c-6afcd1025b18%40owasp.org.
Reading back through this, I would like to offer a clarification.
- ESAPI logging delegates to SLF4J
- As with all of the ESAPI LogFactory implementations, you must use the ESAPI Logging API in your application to gain the benefits.
The way the subject line reads and from the logging snippets you've offered I get the impression you're using the SLF4J logging API in your application and want to have ESAPI receive the log message and escape it?
The behavior is actually inverse from that. Your application must use the ESAPI Logging API, and the ESAPI Logger can delegate to a configured SLF4J configuration.
The escaping happens before SLF4J, not after.
Please let me know if that changes the issue at all. I will do my best to continue debugging this evening.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/e2b32ca3-aafd-4125-978c-6afcd1025b18%40owasp.org.
On Monday, October 14, 2019 at 3:56:53 AM UTC-7, Jeremiah Stacey wrote:Reading back through this, I would like to offer a clarification.
- ESAPI logging delegates to SLF4J
- As with all of the ESAPI LogFactory implementations, you must use the ESAPI Logging API in your application to gain the benefits.
The way the subject line reads and from the logging snippets you've offered I get the impression you're using the SLF4J logging API in your application and want to have ESAPI receive the log message and escape it?
The behavior is actually inverse from that. Your application must use the ESAPI Logging API, and the ESAPI Logger can delegate to a configured SLF4J configuration.
The escaping happens before SLF4J, not after.
Please let me know if that changes the issue at all. I will do my best to continue debugging this evening.
I see. Yes, that completely changes the issue. I was under the impression I could get this done without any code changes, but the result is exactly the opposite. It might have been reasonable if the ESAPI logging interface was functionally identical to the slf4j interface, but it is not.
Besides changing the package for Logger and LogFactory, I will have to change every single log call that takes parameters into the string, which is almost all of them.
We extensively use the slf4j feature that allows "late evaluation" of the format parameters, which saves some performance for things like the "debug" logging level, when "info" level is typically used by default.
https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/index.html
In your log4j2 configuration,you can use the `%enc{%m}` syntax to
encode your message body which will prevent certain characters
from rendering in your logs.
https://logging.apache.org/log4j/2.x/manual/layouts.html
Search for 'encode{pattern}' on the page for more information on the specific characters.
Hope that some of these ideas at least are a bit helpful.Best regards,
-kevin
--
You received this message because you are subscribed to the Google Groups "ESAPI Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to esapi-project-u...@owasp.org.
To view this discussion on the web visit https://groups.google.com/a/owasp.org/d/msgid/esapi-project-users/CAOPE6PhLzKsX4PR%3Dd5Ah5_uWGN1nrso%2BOWk91gzAc9TmYK2NQQ%40mail.gmail.com.