Conversation
…pared statment for better code readability, higher performance sql injection proof queries to db
| // Log the result count if verbose logging is enabled | ||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Account accounts', accounts ? accounts.length : accounts, 'skip', skip) | ||
| Logger.mainLogger.debug('Account accounts', accounts.length, 'skip', skip, 'limit', limit); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the problem, we need to sanitize the skip parameter before logging it. This can be done by removing any newline characters from the skip parameter using String.prototype.replace. This ensures that the log entry cannot be manipulated by injecting special characters.
- In the file
src/dbstore/accounts.ts, sanitize theskipparameter before logging it. - Add a utility function to sanitize user input by removing newline characters.
- Use this utility function to sanitize the
skipparameter before logging it.
| @@ -233,3 +233,4 @@ | ||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Account accounts', accounts.length, 'skip', skip, 'limit', limit); | ||
| const sanitizedSkip = String(skip).replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.debug('Account accounts', accounts.length, 'skip', sanitizedSkip, 'limit', limit); | ||
| } |
|
|
||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.cycleRecord.counter, cycle.cycleMarker) | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.counter, marker); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the log injection issue, we need to sanitize the cycle.counter value before logging it. Specifically, we should remove any newline characters from the cycle.counter value to prevent log injection attacks. This can be done using the String.prototype.replace method.
| @@ -90,3 +90,4 @@ | ||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.counter, marker); | ||
| const sanitizedCounter = String(cycle.counter).replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.debug('Updated cycle for counter', sanitizedCounter, marker); | ||
| } |
|
|
||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.cycleRecord.counter, cycle.cycleMarker) | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.counter, marker); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the log injection issue, we need to sanitize the marker variable before logging it. This can be done by removing any newline characters from the marker string using String.prototype.replace. This ensures that user input cannot inject new log entries.
| @@ -90,3 +90,4 @@ | ||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.counter, marker); | ||
| const sanitizedMarker = marker.replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.debug('Updated cycle for counter', cycle.counter, sanitizedMarker); | ||
| } |
| Logger.mainLogger.error(e) | ||
| Logger.mainLogger.error('Unable to update Cycle', cycle.cycleMarker) | ||
| Logger.mainLogger.error(e); | ||
| Logger.mainLogger.error('Unable to update Cycle', marker); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the log injection issue, we need to sanitize the marker variable before logging it. This can be done by removing any newline characters from the marker string. We will use the String.prototype.replace method to achieve this. The changes will be made in the updateCycle function in the src/dbstore/cycles.ts file.
| @@ -94,3 +94,4 @@ | ||
| Logger.mainLogger.error(e); | ||
| Logger.mainLogger.error('Unable to update Cycle', marker); | ||
| const sanitizedMarker = marker.replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.error('Unable to update Cycle', sanitizedMarker); | ||
| } |
| } | ||
|
|
||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Receipt receipts', receipts.length, 'skip', skip); |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the problem, we need to sanitize the skip parameter before logging it. This can be done by converting the skip parameter to a string and removing any newline characters. This ensures that the log entry cannot be manipulated by injecting special characters.
- In the
queryReceiptsfunction, sanitize theskipparameter before logging it. - Use
String.prototype.replaceto remove any newline characters from theskipparameter. - Ensure that the sanitized
skipparameter is used in the log statement.
| @@ -267,3 +267,4 @@ | ||
| if (config.VERBOSE) { | ||
| Logger.mainLogger.debug('Receipt receipts', receipts.length, 'skip', skip); | ||
| const sanitizedSkip = String(skip).replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.debug('Receipt receipts', receipts.length, 'skip', sanitizedSkip); | ||
| } |
| 'Transaction transactions', | ||
| transactions ? transactions.length : transactions, | ||
| 'skip', | ||
| skip |
Check warning
Code scanning / CodeQL
Log injection Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the log injection issue, we need to sanitize the skip parameter before logging it. Specifically, we should remove any newline characters from the skip parameter to prevent log injection. This can be done using String.prototype.replace to ensure no line endings are present in the user input.
| @@ -202,2 +202,3 @@ | ||
| if (config.VERBOSE) { | ||
| const sanitizedSkip = String(skip).replace(/\n|\r/g, ""); | ||
| Logger.mainLogger.debug( | ||
| @@ -206,3 +207,3 @@ | ||
| 'skip', | ||
| skip | ||
| sanitizedSkip | ||
| ); |
| lastUpdateNeeded = true | ||
| } | ||
| } catch (e) { | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
Add more info to this error message than just the error itself
|
|
||
|
|
||
|
|
||
| // /** |
There was a problem hiding this comment.
remove commented out code if no longer needed
| data: DeSerializeFromJsonString(dbAccount.data), | ||
| })); | ||
| } catch (e) { | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
Add a more detailed error message
| data: DeSerializeFromJsonString(dbAccount.data), | ||
| })); | ||
| } catch (e) { | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add a more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return [] | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return [] | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| return count; | ||
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| return result ? result['COUNT(*)'] || 0 : 0; | ||
| } catch (e) { | ||
| console.log(e) | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| }); | ||
| } catch (e) { | ||
| console.log(e) | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| return originalTxData as OriginalTxData | null; | ||
| } catch (e) { | ||
| console.log(e) | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } | ||
| } | ||
| } catch (e) { | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return null | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return null | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return null | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
Add more detailed error message
| } catch (e) { | ||
| Logger.mainLogger.error(e) | ||
| return null | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
| } | ||
| } catch (e) { | ||
| console.log(e) | ||
| Logger.mainLogger.error(e); |
There was a problem hiding this comment.
add more detailed error message
urnotsam
left a comment
There was a problem hiding this comment.
looks good. mostly missing detailed error messages in catches but since these existed previously I wont hold up this PR for it
Added prepared statements everywhere in archiver
now it's faster and secured against sql injections