Skip to content

Commit 09eca3f

Browse files
XananasX7orr-a-securityMzack9999dogancanbakirdependabot[bot]
authored
chore: remove direct json-iterator dependency (#1386)
* added eviction strategy * added tests for eviction strategy * Revert "feat(server) added eviction strategy" * chore(deps): bump github.com/refraction-networking/utls Bumps [github.com/refraction-networking/utls](https://github.com/refraction-networking/utls) from 1.8.0 to 1.8.2. - [Release notes](https://github.com/refraction-networking/utls/releases) - [Commits](refraction-networking/utls@v1.8.0...v1.8.2) --- updated-dependencies: - dependency-name: github.com/refraction-networking/utls dependency-version: 1.8.2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * fix: return 252 for SMTP VRFY instead of 502 (fixes #991) The smtpd library hard-codes '502 Command not implemented' for VRFY. Per RFC 5321 §3.5.1, a server that cannot verify a mailbox SHOULD return 252 ('Cannot VRFY user, but will accept message and attempt delivery') instead. Returning 502 causes clients such as curl to abort the session before issuing the DATA command, resulting in emails being silently dropped. Fix: point git.mills.io/prologic/smtpd at a patched fork via a go.mod replace directive. The fork is a minimal, single-commit patch on top of the upstream smtpd commit that changes only the VRFY case. * chore: replace direct json-iterator usage with encoding/json Migrates all direct uses of github.com/json-iterator/go in non-test and test files to encoding/json, making json-iterator indirect-only (it remains transitively via an upstream dep). This is part of the projectdiscovery/nuclei#7458 dependency-reduction effort: nuclei's PR #7457 already removed json-iterator from nuclei's direct deps, but json-iterator remained a direct dep of interactsh (exposed through pkg/client.Client), which kept it in nuclei's indirect dep tree. Files changed: - cmd/interactsh-client/main.go - pkg/client/client.go (also converts UnmarshalFromString → json.Unmarshal([]byte(...))) - pkg/server/{dns,ftp,http,ldap,responder,smb,smtp}_server.go - pkg/storage/roundtrip_test.go * merge dev * guard overflow --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Orr Kapel <orr.k@litt.security> Co-authored-by: Mzack9999 <mzack9999@protonmail.com> Co-authored-by: Dogan Can Bakir <65292895+dogancanbakir@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: XananasX7 <XananasX7@users.noreply.github.com>
1 parent b25fc58 commit 09eca3f

11 files changed

Lines changed: 61 additions & 54 deletions

File tree

cmd/interactsh-client/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"os/signal"
@@ -10,7 +11,6 @@ import (
1011
"strings"
1112
"time"
1213

13-
jsoniter "github.com/json-iterator/go"
1414
asnmap "github.com/projectdiscovery/asnmap/libs"
1515
"github.com/projectdiscovery/goflags"
1616
"github.com/projectdiscovery/gologger"
@@ -266,7 +266,7 @@ func main() {
266266
}
267267
}
268268
} else {
269-
b, err := jsoniter.Marshal(interaction)
269+
b, err := json.Marshal(interaction)
270270
if err != nil {
271271
gologger.Error().Msgf("Could not marshal json output: %s\n", err)
272272
} else {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/docker/go-units v0.5.0
1010
github.com/goburrow/cache v0.1.4
1111
github.com/google/uuid v1.6.0
12-
github.com/json-iterator/go v1.1.12
1312
github.com/libdns/libdns v1.1.1
1413
github.com/mackerelio/go-osstat v0.2.6
1514
github.com/miekg/dns v1.1.68
@@ -87,6 +86,7 @@ require (
8786
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
8887
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
8988
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
89+
github.com/json-iterator/go v1.1.12 // indirect
9090
github.com/klauspost/compress v1.18.2 // indirect
9191
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
9292
github.com/klauspost/pgzip v1.2.6 // indirect

pkg/client/client.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"crypto/sha256"
1111
"crypto/x509"
1212
"encoding/base64"
13+
"encoding/json"
1314
"encoding/pem"
15+
"errors"
1416
"fmt"
1517
"io"
1618
"net"
@@ -22,10 +24,7 @@ import (
2224
"sync/atomic"
2325
"time"
2426

25-
"errors"
26-
2727
"github.com/google/uuid"
28-
jsoniter "github.com/json-iterator/go"
2928
asnmap "github.com/projectdiscovery/asnmap/libs"
3029
"github.com/projectdiscovery/gologger"
3130
"github.com/projectdiscovery/interactsh/pkg/options"
@@ -270,7 +269,7 @@ func encodeRegistrationRequest(publicKey, secretkey, correlationID string) ([]by
270269
CorrelationID: correlationID,
271270
}
272271

273-
data, err := jsoniter.Marshal(register)
272+
data, err := json.Marshal(register)
274273
if err != nil {
275274
return nil, errkit.Wrap(err, "could not marshal register request")
276275
}
@@ -457,7 +456,7 @@ func (c *Client) getInteractions(callback InteractionCallback) error {
457456
return fmt.Errorf("could not poll interactions: %s", string(data))
458457
}
459458
response := &server.PollResponse{}
460-
if err := jsoniter.NewDecoder(resp.Body).Decode(response); err != nil {
459+
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
461460
gologger.Error().Msgf("Could not decode interactions: %v\n", err)
462461
return err
463462
}
@@ -470,7 +469,7 @@ func (c *Client) getInteractions(callback InteractionCallback) error {
470469
}
471470
plaintext = bytes.TrimRight(plaintext, " \t\r\n")
472471
interaction := &server.Interaction{}
473-
if err := jsoniter.Unmarshal(plaintext, interaction); err != nil {
472+
if err := json.Unmarshal(plaintext, interaction); err != nil {
474473
gologger.Error().Msgf("Could not unmarshal interaction data interaction: %v\n", err)
475474
continue
476475
}
@@ -479,7 +478,7 @@ func (c *Client) getInteractions(callback InteractionCallback) error {
479478

480479
for _, plaintext := range response.Extra {
481480
interaction := &server.Interaction{}
482-
if err := jsoniter.UnmarshalFromString(plaintext, interaction); err != nil {
481+
if err := json.Unmarshal([]byte(plaintext), interaction); err != nil {
483482
gologger.Error().Msgf("Could not unmarshal interaction data interaction: %v\n", err)
484483
continue
485484
}
@@ -492,7 +491,7 @@ func (c *Client) getInteractions(callback InteractionCallback) error {
492491
continue
493492
}
494493
interaction := &server.Interaction{}
495-
if err := jsoniter.UnmarshalFromString(data, interaction); err != nil {
494+
if err := json.Unmarshal([]byte(data), interaction); err != nil {
496495
gologger.Error().Msgf("Could not unmarshal interaction data interaction: %v\n", err)
497496
continue
498497
}
@@ -564,7 +563,7 @@ func (c *Client) Close() error {
564563
CorrelationID: c.correlationID,
565564
SecretKey: c.secretKey,
566565
}
567-
data, err := jsoniter.Marshal(register)
566+
data, err := json.Marshal(register)
568567
if err != nil {
569568
return errkit.Wrap(err, "could not marshal deregister request")
570569
}
@@ -634,7 +633,7 @@ func (c *Client) performRegistration(serverURL string, payload []byte) error {
634633
return fmt.Errorf("could not register to server: %s", string(data))
635634
}
636635
response := make(map[string]interface{})
637-
if err := jsoniter.NewDecoder(resp.Body).Decode(&response); err != nil {
636+
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
638637
return errkit.Wrap(err, "could not register to server")
639638
}
640639
message, ok := response["message"]

pkg/server/ftp_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
jsoniter "github.com/json-iterator/go"
12+
"encoding/json"
1313
"github.com/projectdiscovery/gologger"
1414
ftpserver "goftp.io/server/v2"
1515
"goftp.io/server/v2/driver/file"
@@ -130,7 +130,7 @@ func (h *FTPServer) recordInteraction(remoteAddress, data string) {
130130
RawRequest: data,
131131
Timestamp: time.Now(),
132132
}
133-
dataBytes, err := jsoniter.Marshal(interaction)
133+
dataBytes, err := json.Marshal(interaction)
134134
if err != nil {
135135
gologger.Warning().Msgf("Could not encode ftp interaction: %s\n", err)
136136
} else {

pkg/server/http_server.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package server
33
import (
44
"crypto/tls"
55
"encoding/base64"
6+
"encoding/json"
67
"fmt"
78
"log"
89
"net"
@@ -16,7 +17,6 @@ import (
1617
"sync/atomic"
1718
"time"
1819

19-
jsoniter "github.com/json-iterator/go"
2020
"github.com/projectdiscovery/gologger"
2121
stringsutil "github.com/projectdiscovery/utils/strings"
2222
)
@@ -157,7 +157,7 @@ func (h *HTTPServer) logger(handler http.Handler) http.HandlerFunc {
157157
RemoteAddress: host,
158158
Timestamp: time.Now(),
159159
}
160-
data, err := jsoniter.Marshal(interaction)
160+
data, err := json.Marshal(interaction)
161161
if err != nil {
162162
gologger.Warning().Msgf("Could not encode root tld http interaction: %s\n", err)
163163
} else {
@@ -217,7 +217,7 @@ func (h *HTTPServer) handleInteraction(r *http.Request, uniqueID, fullID, reqStr
217217
RemoteAddress: hostPort,
218218
Timestamp: time.Now(),
219219
}
220-
data, err := jsoniter.Marshal(interaction)
220+
data, err := json.Marshal(interaction)
221221
if err != nil {
222222
gologger.Warning().Msgf("Could not encode http interaction: %s\n", err)
223223
} else {
@@ -382,7 +382,7 @@ type RegisterRequest struct {
382382
// registerHandler is a handler for client register requests
383383
func (h *HTTPServer) registerHandler(w http.ResponseWriter, req *http.Request) {
384384
r := &RegisterRequest{}
385-
if err := jsoniter.NewDecoder(req.Body).Decode(r); err != nil {
385+
if err := json.NewDecoder(req.Body).Decode(r); err != nil {
386386
gologger.Warning().Msgf("Could not decode json body: %s\n", err)
387387
jsonError(w, fmt.Sprintf("could not decode json body: %s", err), http.StatusBadRequest)
388388
return
@@ -410,7 +410,7 @@ type DeregisterRequest struct {
410410
// deregisterHandler is a handler for client deregister requests
411411
func (h *HTTPServer) deregisterHandler(w http.ResponseWriter, req *http.Request) {
412412
r := &DeregisterRequest{}
413-
if err := jsoniter.NewDecoder(req.Body).Decode(r); err != nil {
413+
if err := json.NewDecoder(req.Body).Decode(r); err != nil {
414414
gologger.Warning().Msgf("Could not decode json body: %s\n", err)
415415
jsonError(w, fmt.Sprintf("could not decode json body: %s", err), http.StatusBadRequest)
416416
return
@@ -476,7 +476,7 @@ func (h *HTTPServer) pollHandler(w http.ResponseWriter, req *http.Request) {
476476
}
477477
response := &PollResponse{Data: data, AESKey: aesKey, TLDData: tlddata, Extra: extradata}
478478

479-
if err := jsoniter.NewEncoder(w).Encode(response); err != nil {
479+
if err := json.NewEncoder(w).Encode(response); err != nil {
480480
gologger.Warning().Msgf("Could not encode interactions for %s: %s\n", ID, err)
481481
jsonError(w, fmt.Sprintf("could not encode interactions: %s", err), http.StatusBadRequest)
482482
return
@@ -505,7 +505,7 @@ func jsonBody(w http.ResponseWriter, key, value string, code int) {
505505
w.Header().Set("Content-Type", "application/json; charset=utf-8")
506506
w.Header().Set("X-Content-Type-Options", "nosniff")
507507
w.WriteHeader(code)
508-
_ = jsoniter.NewEncoder(w).Encode(map[string]interface{}{key: value})
508+
_ = json.NewEncoder(w).Encode(map[string]interface{}{key: value})
509509
}
510510

511511
func jsonError(w http.ResponseWriter, err string, code int) {
@@ -540,5 +540,5 @@ func (h *HTTPServer) metricsHandler(w http.ResponseWriter, req *http.Request) {
540540

541541
w.Header().Set("Content-Type", "application/json; charset=utf-8")
542542
w.Header().Set("X-Content-Type-Options", "nosniff")
543-
_ = jsoniter.NewEncoder(w).Encode(interactMetrics)
543+
_ = json.NewEncoder(w).Encode(interactMetrics)
544544
}

pkg/server/http_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"crypto/tls"
88
"crypto/x509"
99
"encoding/base64"
10+
"encoding/json"
1011
"encoding/pem"
1112
"io"
1213
"net/http"
@@ -17,7 +18,6 @@ import (
1718
"time"
1819

1920
"github.com/google/uuid"
20-
jsoniter "github.com/json-iterator/go"
2121
"github.com/projectdiscovery/interactsh/pkg/storage"
2222
"github.com/rs/xid"
2323
"github.com/stretchr/testify/require"
@@ -117,7 +117,7 @@ func TestSessionTotalMetric(t *testing.T) {
117117
secretKey := uuid.New().String()
118118

119119
// --- Register ---
120-
regBody, err := jsoniter.Marshal(&RegisterRequest{
120+
regBody, err := json.Marshal(&RegisterRequest{
121121
PublicKey: pubB64,
122122
SecretKey: secretKey,
123123
CorrelationID: correlationID,
@@ -132,7 +132,7 @@ func TestSessionTotalMetric(t *testing.T) {
132132
require.Equal(t, int64(1), atomic.LoadInt64(&stats.SessionsTotal), "sessions_total should be 1 after register")
133133

134134
// --- Deregister ---
135-
deregBody, err := jsoniter.Marshal(&DeregisterRequest{
135+
deregBody, err := json.Marshal(&DeregisterRequest{
136136
SecretKey: secretKey,
137137
CorrelationID: correlationID,
138138
})

pkg/server/ldap_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync/atomic"
88
"time"
99

10-
jsoniter "github.com/json-iterator/go"
10+
"encoding/json"
1111
"github.com/projectdiscovery/gologger"
1212
ldap "github.com/projectdiscovery/ldapserver"
1313
stringsutil "github.com/projectdiscovery/utils/strings"
@@ -144,7 +144,7 @@ func (ldapServer *LDAPServer) handleInteraction(uniqueID, fullID, reqString, hos
144144
RemoteAddress: host,
145145
Timestamp: time.Now(),
146146
}
147-
data, err := jsoniter.Marshal(interaction)
147+
data, err := json.Marshal(interaction)
148148
if err != nil {
149149
gologger.Warning().Msgf("Could not encode ldap interaction: %s\n", err)
150150
} else {
@@ -410,7 +410,7 @@ func (ldapServer *LDAPServer) logInteraction(interaction Interaction) {
410410
// Correlation id doesn't apply here, we skip encryption
411411
interaction.Protocol = "ldap"
412412
interaction.Timestamp = time.Now()
413-
data, err := jsoniter.Marshal(interaction)
413+
data, err := json.Marshal(interaction)
414414
if err != nil {
415415
gologger.Warning().Msgf("Could not encode ldap interaction: %s\n", err)
416416
} else {

pkg/server/ntlm_capture.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/binary"
66
"encoding/hex"
7+
"encoding/json"
78
"errors"
89
"fmt"
910
"sync/atomic"
@@ -12,7 +13,6 @@ import (
1213
"github.com/Mzack9999/goimpacket/pkg/ntlm"
1314
"github.com/Mzack9999/goimpacket/pkg/relay"
1415
"github.com/Mzack9999/goimpacket/pkg/utf16le"
15-
jsoniter "github.com/json-iterator/go"
1616
"github.com/projectdiscovery/gologger"
1717
)
1818

@@ -80,7 +80,7 @@ func runNTLMCapture(ctx context.Context, srv relay.ProtocolServer, protocolName
8080
RemoteAddress: auth.SourceAddr,
8181
Timestamp: time.Now(),
8282
}
83-
data, err := jsoniter.Marshal(interaction)
83+
data, err := json.Marshal(interaction)
8484
if err != nil {
8585
gologger.Warning().Msgf("Could not encode %s interaction: %s\n", protocolName, err)
8686
} else {

pkg/server/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package server
22

33
import (
4+
"encoding/json"
45
"net"
56
"strconv"
67
"strings"
78

8-
jsoniter "github.com/json-iterator/go"
99
"github.com/projectdiscovery/gologger"
1010
)
1111

@@ -61,7 +61,7 @@ func formatAddress(host string, port int) string {
6161
// Each protocol handler builds its own protocol-specific Interaction and delegates the marshal/log/store
6262
// step here so every match is stored independently (see issue #1362).
6363
func (options *Options) storeInteraction(interaction *Interaction, correlationID string) {
64-
data, err := jsoniter.Marshal(interaction)
64+
data, err := json.Marshal(interaction)
6565
if err != nil {
6666
gologger.Warning().Msgf("Could not encode %s interaction: %s\n", interaction.Protocol, err)
6767
return
@@ -75,7 +75,7 @@ func (options *Options) storeInteraction(interaction *Interaction, correlationID
7575
// storeRootTLDInteraction marshals interaction and persists it under id via Storage.AddInteractionWithId.
7676
// Used when RootTLD is enabled and the request targets a configured parent domain directly.
7777
func (options *Options) storeRootTLDInteraction(interaction *Interaction, id string) {
78-
data, err := jsoniter.Marshal(interaction)
78+
data, err := json.Marshal(interaction)
7979
if err != nil {
8080
gologger.Warning().Msgf("Could not encode root tld %s interaction: %s\n", interaction.Protocol, err)
8181
return

0 commit comments

Comments
 (0)