Skip to content

Commit

Permalink
Fixed auth support in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiy-skalelabs committed Nov 30, 2023
1 parent b925a73 commit c6794b0
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions npms/skale-owasp/owaspUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export function toFloat( value ) {
}

export function validateURL( s ) {
const u = toURL( s );
if( u == null )
const url = toURL( s );
if( url == null )
return false;
return true;
}
Expand All @@ -155,20 +155,20 @@ export function toURL( s ) {
const cnt = s.length;
if( s[cnt - 1] == sc ) {
const ss = s.substring( 1, cnt - 1 );
const u = toURL( ss );
if( u != null && u != undefined )
u.strStrippedStringComma = sc;
return u;
const url = toURL( ss );
if( url != null && url != undefined )
url.strStrippedStringComma = sc;
return url;
}
return null;
}
const u = new URL( s );
if( !u.hostname )
const url = new URL( s );
if( !url.hostname )
return null;
if( u.hostname.length === 0 )
if( url.hostname.length === 0 )
return null;
u.strStrippedStringComma = null;
return u;
url.strStrippedStringComma = null;
return url;
} catch ( err ) {
return null;
}
Expand All @@ -177,10 +177,10 @@ export function toURL( s ) {
export function toStringURL( s, defValue ) {
defValue = defValue || "";
try {
const u = toURL( s );
if( u == null || u == undefined )
const url = toURL( s );
if( url == null || url == undefined )
return defValue;
return u.toString();
return url.toString();
} catch ( err ) {
return defValue;
}
Expand All @@ -190,8 +190,8 @@ export function isUrlHTTP( strURL ) {
try {
if( !validateURL( strURL ) )
return false;
const u = new URL( strURL );
if( u.protocol == "http:" || u.protocol == "https:" )
const url = new URL( strURL );
if( url.protocol == "http:" || url.protocol == "https:" )
return true;
} catch ( err ) {
}
Expand All @@ -202,8 +202,8 @@ export function isUrlWS( strURL ) {
try {
if( !validateURL( strURL ) )
return false;
const u = new URL( strURL );
if( u.protocol == "ws:" || u.protocol == "wss:" )
const url = new URL( strURL );
if( url.protocol == "ws:" || url.protocol == "wss:" )
return true;
} catch ( err ) {
}
Expand Down Expand Up @@ -291,16 +291,16 @@ export function verifyArgumentWithNonEmptyValue( joArg ) {
export function verifyArgumentIsURL( joArg ) {
try {
verifyArgumentWithNonEmptyValue( joArg );
const u = toURL( joArg.value );
if( u == null ) {
const url = toURL( joArg.value );
if( url == null ) {
console.log(
cc.fatal( "(OWASP) CRITICAL ERROR:" ) + cc.error( " value " ) +
cc.warning( joArg.value ) + cc.error( " of argument " ) + cc.info( joArg.name ) +
cc.error( " must be valid URL" )
);
process.exit( 126 );
}
if( u.hostname.length <= 0 ) {
if( url.hostname.length <= 0 ) {
console.log( cc.fatal(
"(OWASP) CRITICAL ERROR:" ) + cc.error( " value " ) + cc.warning( joArg.value ) +
cc.error( " of argument " ) + cc.info( joArg.name ) +
Expand Down Expand Up @@ -729,14 +729,14 @@ export function fnAddressImpl_() {
}

export function getEthersProviderFromURL( strURL ) {
const u = new URL( strURL );
const url = new URL( strURL );
let userName = null, userPwd = null;
if( u.username ) {
userName = u.username;
userPwd = u.password;
u.username = "";
u.password = "";
strURL = u.href; // remove credentials
if( url.username ) {
userName = url.username;
userPwd = url.password;
url.username = "";
url.password = "";
strURL = url.href; // remove credentials
}
const joConnectionInfo = { // see https://docs.ethers.io/v5/api/utils/web/#ConnectionInfo
url: strURL,
Expand Down

0 comments on commit c6794b0

Please sign in to comment.