Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hizla
waitlist
backend
Commits
52c3efc7
Commit
52c3efc7
authored
10 months ago
by
Levatax
Browse files
Options
Downloads
Patches
Plain Diff
fix(api): apply limiter to register route and move logic to limiter.go
parent
217dee64
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!9
fix(api): apply limiter to register route and move logic to limiter.go
Pipeline
#978
passed
10 months ago
Stage: lint
Stage: test
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.go
+0
-14
0 additions, 14 deletions
app.go
limiter.go
+22
-0
22 additions, 0 deletions
limiter.go
register.go
+1
-1
1 addition, 1 deletion
register.go
with
23 additions
and
15 deletions
app.go
+
0
−
14
View file @
52c3efc7
...
...
@@ -6,12 +6,10 @@ import (
"net"
"os"
"sync/atomic"
"time"
"github.com/gofiber/contrib/hcaptcha"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/cors"
"github.com/gofiber/fiber/v3/middleware/limiter"
"github.com/syndtr/goleveldb/leveldb"
)
...
...
@@ -24,18 +22,6 @@ func serve(sig chan os.Signal, db *leveldb.DB) error {
AllowHeaders
:
[]
string
{
"Origin"
,
"Content-Type"
,
"Accept"
},
}))
// rate limiting
app
.
Use
(
limiter
.
New
(
limiter
.
Config
{
Max
:
5
,
Expiration
:
7
*
24
*
time
.
Hour
,
// 1 week expiration
LimitReached
:
func
(
c
fiber
.
Ctx
)
error
{
log
.
Printf
(
"Rate limit exceeded for IP: %s"
,
c
.
IP
())
return
c
.
Status
(
fiber
.
StatusTooManyRequests
)
.
JSON
(
fiber
.
Map
{
"message"
:
"Rate limit exceeded. Max 5 registrations per week."
,
})
},
}))
var
captcha
fiber
.
Handler
hCaptchaEnable
:=
conf
[
hCaptchaSiteKey
]
!=
"unset"
&&
conf
[
hCaptchaSecretKey
]
!=
"unset"
...
...
This diff is collapsed.
Click to expand it.
limiter.go
0 → 100644
+
22
−
0
View file @
52c3efc7
package
main
import
(
"log"
"time"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/limiter"
)
func
rateLimiter
()
fiber
.
Handler
{
return
limiter
.
New
(
limiter
.
Config
{
Max
:
5
,
Expiration
:
7
*
24
*
time
.
Hour
,
// 1 week expiration
LimitReached
:
func
(
c
fiber
.
Ctx
)
error
{
log
.
Printf
(
"Rate limit exceeded for IP: %s"
,
c
.
IP
())
return
c
.
Status
(
fiber
.
StatusTooManyRequests
)
.
JSON
(
fiber
.
Map
{
"message"
:
"Rate limit exceeded. Max 5 registrations per week."
,
})
},
})
}
This diff is collapsed.
Click to expand it.
register.go
+
1
−
1
View file @
52c3efc7
...
...
@@ -19,7 +19,7 @@ type registration struct {
// Waitlist registration route
func
routeRegister
(
app
*
fiber
.
App
,
p
string
,
db
*
leveldb
.
DB
,
count
*
atomic
.
Uint64
,
captcha
fiber
.
Handler
)
{
app
.
Post
(
p
,
func
(
c
fiber
.
Ctx
)
error
{
app
.
Post
(
p
,
rateLimiter
(),
func
(
c
fiber
.
Ctx
)
error
{
t
:=
time
.
Now
()
.
UTC
()
req
:=
new
(
registration
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment