-
Notifications
You must be signed in to change notification settings - Fork 339
fix(clerk-js): Incomplete string escaping or encoding within password complexity #5786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ng or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 50476de The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -13,8 +13,8 @@ | |||
let specialCharsRegex: RegExp; | |||
if (config.allowed_special_characters) { | |||
// Avoid a nested group by escaping the `[]` characters | |||
let escaped = config.allowed_special_characters.replace('[', '\\['); | |||
escaped = escaped.replace(']', '\\]'); | |||
let escaped = config.allowed_special_characters.replace(/\[/g, '\\['); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
To fix the issue, we need to ensure that backslashes in the allowed_special_characters
string are properly escaped before constructing the regular expression. This can be achieved by adding a replace
call to escape backslashes (\
) before escaping square brackets ([
and ]
). The updated code will replace each backslash with a double backslash (\\
), ensuring that the resulting regex is valid and behaves as intended.
The changes will be made in the createTestComplexityCases
function, specifically in the block where allowed_special_characters
is processed (lines 15–18). No additional imports or dependencies are required.
-
Copy modified lines R15-R17
@@ -14,4 +14,5 @@ | ||
if (config.allowed_special_characters) { | ||
// Avoid a nested group by escaping the `[]` characters | ||
let escaped = config.allowed_special_characters.replace(/\[/g, '\\['); | ||
// Avoid a nested group by escaping backslashes and the `[]` characters | ||
let escaped = config.allowed_special_characters.replace(/\\/g, '\\\\'); | ||
escaped = escaped.replace(/\[/g, '\\['); | ||
escaped = escaped.replace(/\]/g, '\\]'); |
let escaped = config.allowed_special_characters.replace('[', '\\['); | ||
escaped = escaped.replace(']', '\\]'); | ||
let escaped = config.allowed_special_characters.replace(/\[/g, '\\['); | ||
escaped = escaped.replace(/\]/g, '\\]'); |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
To fix the issue, we need to ensure that backslashes in the allowed_special_characters
string are properly escaped before constructing the regular expression. This can be achieved by adding an additional replace
call to escape backslashes (\
) before escaping square brackets ([
and ]
). The g
flag should be used in the regular expression to ensure all occurrences are replaced.
The updated code will:
- First escape all backslashes by replacing each
\
with\\
. - Then escape square brackets (
[
and]
) as before.
This ensures that the resulting string is safe to use in a regular expression.
-
Copy modified lines R16-R17
@@ -15,3 +15,4 @@ | ||
// Avoid a nested group by escaping the `[]` characters | ||
let escaped = config.allowed_special_characters.replace(/\[/g, '\\['); | ||
let escaped = config.allowed_special_characters.replace(/\\/g, '\\\\'); | ||
escaped = escaped.replace(/\[/g, '\\['); | ||
escaped = escaped.replace(/\]/g, '\\]'); |
Potential fix for https://github.com/clerk/javascript/security/code-scanning/6
To fix the issue, we need to ensure that all occurrences of
]
in theallowed_special_characters
string are escaped. This can be achieved by using a regular expression with the global (g
) flag in thereplace
method. Similarly, the same approach should be applied to the[
character for consistency and correctness.The updated code will replace:
with:
Additionally, the replacement for
[
should also use a regular expression with theg
flag:This ensures that all occurrences of both
[
and]
are escaped.Suggested fixes powered by Copilot Autofix. Review carefully before merging.