Skip to content

Commit

Permalink
fix/disable OTP caching (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindHunter86 authored Sep 25, 2024
2 parents 0eb2348 + 8cec9d2 commit c217824
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/proxy/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (m *Validator) ValidateRequest() (e error) {
return errors.New("invalid query detected")
}

if m.isQueryBypassListed() {
m.customs = m.customs | CHCacheBypass
}

// delete or update cache key for futher request processing
// controlled by CustomHeaders
m.postValidationMutate(m.requestArgs.QueryString())
Expand Down Expand Up @@ -238,7 +242,7 @@ var declinedKeysPool = sync.Pool{

func (m *Validator) isArgsWhitelisted() (_ bool) {
// []string pool without allocations
// researched from https://vk.cc/cys872
// researched here - https://vk.cc/cys872
declinedKeysPtr := declinedKeysPool.Get().(*[]string)
declinedKeys := *declinedKeysPtr

Expand Down Expand Up @@ -279,6 +283,16 @@ func (m *Validator) isQueryWhitelisted() (ok bool) {
return
}

func (m *Validator) isQueryBypassListed() (ok bool) {
var query []byte
if query = m.requestArgs.PeekBytes([]byte("query")); len(query) == 0 {
return true
}

_, ok = queryBypasslist[futils.UnsafeString(query)]
return ok
}

func (m *Validator) queryLookup(equal []byte) (_ bool) {
var query []byte
if query = m.requestArgs.PeekBytes([]byte("query")); len(query) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions internal/proxy/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ var queryWhitelist = map[string]interface{}{
"auth_accept_otp": nil,
"auth_login_otp": nil,
}

var queryBypasslist = map[string]interface{}{
"auth_get_otp": nil,
"auth_accept_otp": nil,
"auth_login_otp": nil,
}

0 comments on commit c217824

Please sign in to comment.