Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finwise-miniapp-be
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ThinhNC
finwise-miniapp-be
Commits
f7cb2ef6
Commit
f7cb2ef6
authored
Jul 24, 2026
by
ThinhNC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
security: make trust proxy and CORS origins configurable
parent
50ef841e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
3 deletions
+34
-3
.env.example
.env.example
+5
-1
app.ts
src/app.ts
+15
-2
env.config.ts
src/config/env.config.ts
+14
-0
No files found.
.env.example
View file @
f7cb2ef6
...
...
@@ -22,4 +22,8 @@ MAIL_SECURE=false
MAIL_USER=your_gmail_user@gmail.com
MAIL_PASS=your_gmail_app_password
MAIL_FROM="FinWise <noreply@gmail.com>"
APP_URL=http://localhost:7777
\ No newline at end of file
APP_URL=http://localhost:7777
TRUST_PROXY=false
ALLOWED_ORIGINS=http://localhost:7777,http://localhost:3000,http://localhost:5173
\ No newline at end of file
src/app.ts
View file @
f7cb2ef6
...
...
@@ -8,13 +8,26 @@ import { errorMiddleware, notFoundMiddleware } from './middlewares/error.middlew
import
routes
from
'./routes'
;
import
{
swaggerSpec
,
swaggerOptions
}
from
'./config/swagger.config'
;
import
{
rateLimitMiddleware
}
from
'./middlewares/rate-limit.middleware'
;
import
{
envConfig
}
from
'./config/env.config'
;
const
app
=
express
();
app
.
set
(
'trust proxy'
,
true
);
app
.
set
(
'trust proxy'
,
envConfig
.
trustProxy
);
app
.
use
(
helmet
({
contentSecurityPolicy
:
false
,
}),);
app
.
use
(
cors
());
const
corsOptions
:
cors
.
CorsOptions
=
{
origin
:
(
origin
,
callback
)
=>
{
const
allowed
=
envConfig
.
cors
.
allowedOrigins
;
if
(
allowed
.
includes
(
'*'
)
||
!
origin
||
allowed
.
includes
(
origin
))
{
callback
(
null
,
true
);
}
else
{
callback
(
null
,
false
);
}
},
credentials
:
true
,
};
app
.
use
(
cors
(
corsOptions
));
app
.
use
(
morgan
(
'dev'
));
app
.
use
(
express
.
json
());
app
.
use
(
express
.
urlencoded
({
extended
:
true
}));
...
...
src/config/env.config.ts
View file @
f7cb2ef6
...
...
@@ -17,4 +17,18 @@ export const envConfig = {
accessExpiresIn
:
process
.
env
.
JWT_ACCESS_EXPIRES_IN
||
'1d'
,
refreshExpiresIn
:
process
.
env
.
JWT_REFRESH_EXPIRES_IN
||
'7d'
,
},
trustProxy
:
(()
=>
{
const
val
=
process
.
env
.
TRUST_PROXY
;
if
(
!
val
)
return
false
;
if
(
val
===
'true'
)
return
true
;
if
(
val
===
'false'
)
return
false
;
if
(
/^
\d
+$/
.
test
(
val
))
return
parseInt
(
val
,
10
);
if
(
val
.
includes
(
','
))
return
val
.
split
(
','
).
map
(
s
=>
s
.
trim
());
return
val
;
})(),
cors
:
{
allowedOrigins
:
process
.
env
.
ALLOWED_ORIGINS
?
process
.
env
.
ALLOWED_ORIGINS
.
split
(
','
).
map
(
s
=>
s
.
trim
())
:
[
'*'
],
},
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment