Skip to content

Commit

Permalink
Merge pull request #122 from azimjohn/Reject-Users-who-joined-github-…
Browse files Browse the repository at this point in the history
…after-2023

[server] Extracting joined_date validation from Authenticate method into serveEventConn
  • Loading branch information
azimjohn authored Apr 5, 2023
2 parents 79cf5ca + 70f4dc6 commit d982c7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
9 changes: 0 additions & 9 deletions server/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"net/url"
"strings"
"time"
)

const tokenPrefix = "gho_"
Expand Down Expand Up @@ -100,14 +99,6 @@ func (g github) Authenticate(token string) (User, error) {
if err != nil {
return user, fmt.Errorf("failed to decode user data: %v", err)
}
date, err := time.Parse(time.RFC3339, user.JoinedDate)
if err != nil {
return user, fmt.Errorf("failed to parse joined date: %v", err)
}

if date.Year() > 2022 {
return user, fmt.Errorf("user joined github after 2022")
}
user.Login = strings.ToLower(user.Login)
return user, nil
}
19 changes: 14 additions & 5 deletions server/jprq.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"bufio"
"errors"
"fmt"
"github.com/azimjohn/jprq/server/config"
"github.com/azimjohn/jprq/server/events"
"github.com/azimjohn/jprq/server/github"
"github.com/azimjohn/jprq/server/server"
"github.com/azimjohn/jprq/server/tunnel"
"io"
"log"
"net"
"os"
"strconv"
"strings"
"time"

"github.com/azimjohn/jprq/server/config"
"github.com/azimjohn/jprq/server/events"
"github.com/azimjohn/jprq/server/github"
"github.com/azimjohn/jprq/server/server"
"github.com/azimjohn/jprq/server/tunnel"
)

const dateFormat = "2006/01/02 15:04:05"
Expand Down Expand Up @@ -112,6 +113,14 @@ func (j *Jprq) serveEventConn(conn net.Conn) error {
if err != nil {
return events.WriteError(conn, "authentication failed")
}
date, err := time.Parse(time.RFC3339, user.JoinedDate)
if err != nil {
return events.WriteError(conn, "Could not parse joined date")
}

if date.Year() > 2022 {
return events.WriteError(conn, "Rejecting login request from user who joined github after 2023; user: %s", user.Login)
}
if reason, found := j.blockedUsers[user.ID]; found {
return events.WriteError(conn, "your account is blocked for %s", reason)
}
Expand Down

0 comments on commit d982c7d

Please sign in to comment.