Coder Social home page Coder Social logo

Comments (11)

emersion avatar emersion commented on July 28, 2024

We want to check and enforce secure connection before AUTH command to prevent credential leak.

That's the default behavior. AllowInsecureAuth will turn that off.

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024

If i understand the source code[1] correctly, with AllowInsecureAuth=false, go-smtp disables AUTH (by not advertising the AUTH support) but it continues the smtp session, right? What we want is terminating or closing the smtp session instead.

go-smtp/conn.go

Lines 253 to 260 in b4236a6

if c.authAllowed() {
authCap := "AUTH"
for name := range c.server.auths {
authCap += " " + name
}
caps = append(caps, authCap)
}

from go-smtp.

emersion avatar emersion commented on July 28, 2024

I don't understand why one would want to advertise AUTH while always sending an error while it's used.

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024

Misconfiguration.

from go-smtp.

emersion avatar emersion commented on July 28, 2024

Please elaborate... If I had to guess, is it to give users a clear error when they try to setup their client but forget to enable encryption?

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024

Hi @emersion

Thanks for the patience and helping.

Our smtp "clients" are multiple MTAs, not MUA. And we force secure smtp connection for secure traffic. If a MTA doesn't enable / establish secure connection, we reject (with a clear error message, of course) and terminate the connection to prevent leaking credentials in AUTH directive until it's properly configured.

In this case, AllowInsecureAuth is not the solution since it continues the session.

Maybe it's better to add some more methods to Session interface to allow developers to handle connection or data in different smtp state, for example:

  • right after connection is established. This is the best state in smtp session to perform IP address or reverse hostname based whitelisting and blacklisting.
  • right after EHLO. Again, HELO hostname based white/blacklisting.
  • right after STARTTLS (it 's called no matter it's secure or insecure connection). Good state to check and enforce secure connection.

Your opinion?

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024

@emersion Any update?

from go-smtp.

emersion avatar emersion commented on July 28, 2024
Insecure suggestion, leaks credentials, do not implement

Right, thanks for explaining, that makes sense. I'd suggest:

  • Set AllowInsecureAuth = true
  • In the Backend's NewSession function, check whether the connection is TLS or not, store that info somewhere in the returned Session, and return an error in AuthPlain.

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024
  • In the Backend's NewSession function, check whether the connection is TLS or not, store that info somewhere in the returned Session, and return an error in AuthPlain.

Hi @emersion,

Thanks for the reply, but this suggestion won't work.

I tested this before created this issue, and double tested moment ago: it doesn't work with STARTTLS.
I used testing code like below:

func (b *Backend) NewSession(conn *smtp.Conn) (session smtp.Session, err error) {
	ip, _, _ := utils.GetIPPortFromNetAddr(conn.Conn().RemoteAddr())

	state, _ := conn.TLSConnectionState()
	fmt.Printf("DEBUG Version: [%s] %d", ip, state.Version)

	// ... omit other testing code here...
  • When client establishes connection, the state.Version is 0 (which means insecure connection)
  • Then client issues STARTTLS smtp directive in same smtp session, NewSession is called again(?) and state.Version is now 772 (TLSv1.3, cipher suite is TLS_AES_128_GCM_SHA256).

Since NewSession is called before STARTTLS directive, we cannot judge whether it's secure in this stage, and smtp.Session doesn't have a public method for starttls directive. So we still have to check this in AuthPlain() which may already leak the account credential sent by AUTH directive.

Can we add more public methods to smtp.Session to handle more smtp stages? e.g. before AUTH.

from go-smtp.

emersion avatar emersion commented on July 28, 2024

What you're asking for protocol-wise is not possible. Clients may send either STARTTLS or AUTH directly, and there is no way to know in advance. If the client decides to send AUTH without STARTTLS, the credentials are leaked.

The AUTH command contains an optional initial response argument, which in the case of PLAIN contains the username/password.

from go-smtp.

iredmail avatar iredmail commented on July 28, 2024

ok, i will live with it. Thanks very much for helping. :)

from go-smtp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.