Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
bfedfebf
Commit
bfedfebf
authored
1 year ago
by
timothycarambat
Browse files
Options
Downloads
Patches
Plain Diff
security: force sanitize env string set by user
parent
2374939f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/utils/helpers/updateENV.js
+11
-3
11 additions, 3 deletions
server/utils/helpers/updateENV.js
with
11 additions
and
3 deletions
server/utils/helpers/updateENV.js
+
11
−
3
View file @
bfedfebf
...
@@ -564,6 +564,16 @@ async function dumpENV() {
...
@@ -564,6 +564,16 @@ async function dumpENV() {
"
DISABLE_TELEMETRY
"
,
"
DISABLE_TELEMETRY
"
,
];
];
// Simple sanitization of each value to prevent ENV injection via newline or quote escaping.
function
sanitizeValue
(
value
)
{
const
offendingChars
=
/
[\n\r\t\v\f\u
0085
\u
00a0
\u
1680
\u
180e
\u
2000-
\u
200a
\u
2028
\u
2029
\u
202f
\u
205f
\u
3000"'`#
]
/
;
const
firstOffendingCharIndex
=
value
.
search
(
offendingChars
);
if
(
firstOffendingCharIndex
===
-
1
)
return
value
;
return
value
.
substring
(
0
,
firstOffendingCharIndex
);
}
for
(
const
key
of
protectedKeys
)
{
for
(
const
key
of
protectedKeys
)
{
const
envValue
=
process
.
env
?.[
key
]
||
null
;
const
envValue
=
process
.
env
?.[
key
]
||
null
;
if
(
!
envValue
)
continue
;
if
(
!
envValue
)
continue
;
...
@@ -572,9 +582,7 @@ async function dumpENV() {
...
@@ -572,9 +582,7 @@ async function dumpENV() {
var
envResult
=
`# Auto-dump ENV from system call on
${
new
Date
().
toTimeString
()}
\n`
;
var
envResult
=
`# Auto-dump ENV from system call on
${
new
Date
().
toTimeString
()}
\n`
;
envResult
+=
Object
.
entries
(
frozenEnvs
)
envResult
+=
Object
.
entries
(
frozenEnvs
)
.
map
(([
key
,
value
])
=>
{
.
map
(([
key
,
value
])
=>
`
${
key
}
='
${
sanitizeValue
(
value
)}
'`
)
return
`
${
key
}
='
${
value
}
'`
;
})
.
join
(
"
\n
"
);
.
join
(
"
\n
"
);
const
envPath
=
path
.
join
(
__dirname
,
"
../../.env
"
);
const
envPath
=
path
.
join
(
__dirname
,
"
../../.env
"
);
...
...
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