-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Added URI sanitization function.
Issue: #3081 PR:
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
monkey/monkey_island/cc/ui/src/utils/sanitizers/uriSanitizer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const REG_EXP_VALIDATORS = [ | ||
{expression: /[()[\]{};`'"]/gmi, expectedTestResult: false}, | ||
{expression: /^([^\w]*)(unsafe|javascript|vbscript|app|admin|icloud-sharing|icloud-vetting|help|aim|facetime-audio|applefeedback|ibooks|macappstore|udoc|ts|st|x-apple-helpbasic)/gmi, expectedTestResult: false}, | ||
{expression: /^(?:\(?:\(?:ht)tps?\):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$)\)/gmi, expectedTestResult: true} | ||
]; | ||
|
||
const GENERAL_UNSAFE_STRINGS = ['javascript:'] | ||
|
||
export const sanitizeURI = (uri) => { | ||
const EMPTY_URI = ''; | ||
|
||
const validators = REG_EXP_VALIDATORS; | ||
for(let i=0; i < validators.length; i++){ | ||
const regTest = new RegExp(validators[i].expression); | ||
if(regTest.test(uri) !== validators[i].expectedTestResult) { | ||
return EMPTY_URI; | ||
} | ||
} | ||
|
||
for(let i=0; i<GENERAL_UNSAFE_STRINGS.length; i++){ | ||
if(uri.indexOf(GENERAL_UNSAFE_STRINGS[i]) !== -1){ | ||
return EMPTY_URI; | ||
} | ||
} | ||
|
||
return uri; | ||
} |