Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Cleaned-up log4j 1.2 that disables scary networking (base=1.2.17, fully binary compatible) #17

Closed
wants to merge 27 commits into from

Conversation

lsimons
Copy link

@lsimons lsimons commented Dec 19, 2021

Conservative version of earlier PR #16. This has full binary and source compatibility and starts of from 1.2.17, not including the non-released changes made many years ago after the release of 1.2.17.

Unlike PR16, this branch is neatly structured as a series of minimal mostly-idempotent patches, that could be accepted step by step:

cleanup-only patches

  1. https://github.com/lsimons/log4j/tree/feat/2021-modern-build: make build work with maven 3
  2. https://github.com/lsimons/log4j/tree/fix/2021-robust-tests: clean up the test suite
  3. https://github.com/lsimons/log4j/tree/feat/2021-update-website: clean up the website
  4. https://github.com/lsimons/log4j/tree/fix/2021-chainsaw-serialVersionUID: binary compatibility for chainsaw package. This change is not contained in PR16, since chainsaw was removed on trunk after the release of 1.2.17.

security fixes

  1. https://github.com/lsimons/log4j/tree/fix/2021-secure-net: conservative source/binary compatible versions of the security fixes to log4j.net from PR16.
  2. https://github.com/lsimons/log4j/tree/fix/2021-secure-jmx: conservative source/binary compatible versions of the security fix to log4j.jmx from PR16.
  3. https://github.com/lsimons/log4j/tree/fix/2021-secure-jdbc: security fix to log4j.jdbc from PR16
  4. https://github.com/lsimons/log4j/tree/fix/2021-secure-erfa: security fix to ExternallyRolledFileAppender from PR16.

bugfixes

  1. https://github.com/lsimons/log4j/tree/fix/2021-mdc-java-version: bugfix to Loader.java/MDC.java to allow it to work properly on JDK >= 9 from PR16 .

Please note that while this PR is filed against trunk, it can't be merged directly because trunk has moved on from 1.2.17. Suggested approach is to make a bugfix 1.2.x branch starting from tag v1_2_17, and then apply these changes to it, and release 1.2.18 from there.

grobmeier and others added 27 commits May 4, 2012 06:52
The new build requires JDK8 or later, and a JDK6 installed as a maven
toolchain.

Main changes include:
* switch to Maven 3, requiring JDK7 to invoke
* switch to latest (compatible) maven plugins, requiring JDK8 to invoke
* introduce two profiles: toolchain (default) and no-toolchain
  * toolchain profile uses maven toolchains feature with JDK6
    (can also use JDK7) and source/target version of 1.4,
    for compatibility with JDK 1.4/5/6/7 and beyond
  * no-toolchain profile uses default system JDK with
    source/target version of 7,
    for compatibility with JDK 8/9/10/11/17 and beyond
* stop building NTEventLogAppender.dll from maven by invoking ant
  (instead use the checked-in version)
* replace some plugin use with resources section
* replace some ant tasks with maven clean plugin
* change all project metadata for correctness
* remove duplicate LICENSE and NOTICE files and use the main ones
* set default encoding to UTF-8 to silence some warnings
* enable running all unit tests instead of a whitelist
* change when and how site is generated
* customize site templating for modern site plugin
* remove unused and unsupported ant build files
* update INSTALL document to match changes
Sets up a matrix build using github actions that runs on every push.
The following combinations all work:

* Toolchain 1.6, JDK 11, OS ubuntu-18.04
* Toolchain 1.6, JDK 11, OS ubuntu-20.04
* Toolchain 1.6, JDK 11, OS windows-2019
* Toolchain 1.6, JDK 11, OS windows-2022
* Toolchain 1.7, JDK 11, OS ubuntu-18.04
* JDK 8, OS ubuntu-18.04
* JDK 11, OS ubuntu-18.04
* JDK 17, OS ubuntu-18.04
* JDK 8, OS ubuntu-20.04
* JDK 11, OS ubuntu-20.04
* JDK 17, OS ubuntu-20.04
* JDK 8, OS windows-2019
* JDK 11, OS windows-2019
* JDK 17, OS windows-2019
* JDK 8, OS windows-2022
* JDK 11, OS windows-2022
* JDK 17, OS windows-2022
Delete several integration-style tests that are broken.
They are not being run by the main build (because they are broken).
Now that the main build runs all tests, remove the old way of running
them with ant or bash.
MDCTestCase has some nasty reflection inside that is not allowed anymore
on JDK >= 17. Detect and trap the error.
Changes most tests to use unique output files during their runs, so that
when they run in parallel or out-of-order or interactively they do not
cause test failures, reducing flakyness of test runs.
Hand-picked changes from trunk
* Remove outdated roadmap page
* Update navigation to link to renamed mailing lists page
* Remove link to non-existent wiki
These changes are incomplete because contributors cannot test the
maven release plugin setup.
Disables:
* JMSAppender
* JMSSink
* SimpleSocketServer
* SocketHubAppender
* SocketServer
* SocketNode
* TelnetAppender

These classes now log an error instead of making network connections.

Their external APIs remain intact to allow code using them to migrate
without blowing up before runtime.

Added tests for their remaining behavior.

Adds warnings:
* for SyslogAppender unless logging to a local loopback address
* for SMTPAppender:
  * Does not warn about safe(r) use talking to the local loopback.
  * If using SMTPS, warn that host will not be verified (CVE-2020-9488).
    Note this commit does not actually fix the security issue. Instead
    it warns an upgrade is needed (or a change in configuration).
  * If using SMTP, warn about an unencrypted protocol.
* deprecation warnings on disablec classes
* deprecation for SocketAppender since it's the client side of the
  disabled server code
Disables:
* jmx.Agent

This class now throws an error instead of making network connections.
Disables:
* JDBCAppender

This class now logs an error instead of making network connections.
Disables networking in:
* ExternallyRolledFileAppender

Behavior reduces to be a normal non-rolling FileAppender.
Avoids trying to determine whether java >= 1.2 since if this version
of the code loads java >= 1.4.
Disable a set of flaky integration tests that depend on specific JDK
behavior (usually due to expecting a specific stack trace), when not
running using the toolchain JDK.
@garydgregory
Copy link
Member

garydgregory commented Dec 19, 2021

A hard -1

Thank you for pitching in but this PR completely breaks major blocks of functionality.

I see comments like "Changed in 1.2.18+ to complain about its use and do nothing else." for the JDBC Appender, Telnet Appender, ExternallyRolledFileAppender, JMS Appender, JMX, and more! 140 files changed? You might want to do one PR per CVE/issue.

The PR says "binary compatible" but that's only because the code has been gutted which will break applications left and right.

This PR is so far out-of-bounds that I have a hard time finding where to start.

1.x is End-Of-Life.

If we do ANYTHING, it would be to address CVEs. We have CVE: CVE-2019-1757. We also have discussed security in the JMS Appender. So that would be two changes to do in two PRs IMO. This PR deals with neither in a meaningful manner.

I see a disconnect between the email and the PR:

"So as requested I've made a conservative fully binary compatible version of
all the build changes and security fixes, patches are on a new pull request
at"

This PR contains ZERO security fixes, it just removes code. For me "conservative" means the least amount of changes, not gutting the code, changing 140 files, and breaking applications with no alternative.

"Trying to have solid network code in 1.x while having it also be binary
compatible is way too much work"

So you've gutted the code because doing real fixes is "too much work". There you have it I guess.

I am not endorsing a 1.2.18 release but if there was consensus on the PMC for resurrection it should be ONLY to address IMO CVE-2019-1757 and the JMS Appender using the same techniques we used in 2.x.

I'll leave it to each person to decide what is "too much work", just note that it took 6 of us working almost full time to work on 2.15.0, 2.16.0, 2.17.0, and 2.12.2.

Keep in mind that this is a low-level library that must be a drop-in replacement in all settings from the largest enterprise to a hobbyist. Hence our choices of remedies in 2.x.

Comment on lines +164 to +185
void warnInCaseOfInsecureSMTP() {
boolean local = false;
if (smtpHost != null) {
try {
if (InetAddress.getByName(smtpHost).isLoopbackAddress()) {
local = true;
}
} catch (UnknownHostException e) {
// hope it'll work out later
}
}
if (!local) {
if ("smtps".equals(smtpProtocol)) {
LogLog.warn("WARN-LOG4J-NETWORKING-REMOTE-SMTPS: logging to remote SMTPS host '" +
smtpHost + "'! Log4J 1.2 cannot verify the host, upgrade to Log4J 2!");
} else {
LogLog.warn("WARN-LOG4J-NETWORKING-REMOTE-SMTP: logging to remote SMTP host '" +
smtpHost + "'! SMTP is an unencrypted protocol.");
}
}
}

Choose a reason for hiding this comment

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

👍🏾

@vlsi vlsi mentioned this pull request Dec 28, 2021
@larrywest
Copy link

larrywest commented Jan 1, 2022

My $0.000002:

Log4j 1.x reached end-of-life long ago - last updated a decade ago.

On August 5, 2015 the Logging Services Project Management Committee announced that Log4j 1.x had reached end of life

From 2019 in re CVE-2019-17571:

... This can provide an attack vector that can be expoited. Since Log4j 1 is no longer maintained this issue will not be fixed. Users are urged to upgrade to Log4j 2.

There's no rationale given here for bringing log4j 1.x back from the dead, and anyone who cares about security or project hygiene has long since moved on to log4j2 or logback.

Assuming there are reasons, why not fork this and call it something else?


Update:

This applies to PR #18, too. I'm only a user — once upon a time of log4j 1.x — not a contributor, but I'm puzzled why there's not a clear statement on either PR justifying reversing the above-cited decisions.

@lsimons
Copy link
Author

lsimons commented Jan 2, 2022

The rationale is not found here because most discussion about what should happen with apache projects happens on mailing lists. In this case, the discussion can be followed (and joined!) on [email protected], archives at https://lists.apache.org/[email protected] , more info at https://logging.apache.org/log4j/2.x/mail-lists.html .

@lsimons
Copy link
Author

lsimons commented Jan 2, 2022

Superceded by #18

@lsimons lsimons closed this Jan 2, 2022
@lsimons
Copy link
Author

lsimons commented Jan 20, 2022

See

for a maintained/released fork with similar security fixes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants