-
Notifications
You must be signed in to change notification settings - Fork 124
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
Kubero V3 refactoring #619
base: main
Are you sure you want to change the base?
Conversation
(WIP) add initial auth function
res.send(template); | ||
} catch (err) { | ||
this.logger.error(err); | ||
res.status(500).send(err); |
Check warning
Code scanning / CodeQL
Information exposure through a stack trace Medium
stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 6 days ago
To fix the problem, we need to ensure that the stack trace and any sensitive information contained in the error object are not exposed to the end user. Instead, we should log the error details on the server and send a generic error message to the user. This can be achieved by modifying the catch block to log the error and send a generic message.
-
Copy modified lines R41-R42
@@ -40,4 +40,4 @@ | ||
} catch (err) { | ||
this.logger.error(err); | ||
res.status(500).send(err); | ||
this.logger.error('Exception occurred', err.stack); | ||
res.status(500).send('An error occurred while processing your request.'); | ||
} |
res.send(template); | ||
} catch (err) { | ||
this.logger.error(err); | ||
res.status(500).send(err); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Exception text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 6 days ago
To fix the problem, we need to ensure that the error message is properly sanitized or escaped before being sent in the response. This can be achieved by using a library like he
(HTML entities) to escape the error message. This will prevent any malicious content from being interpreted as HTML.
- Install the
he
library to handle HTML escaping. - Import the
he
library in thetemplates.controller.ts
file. - Use the
he.escape
function to escape the error message before sending it in the response.
-
Copy modified line R12 -
Copy modified line R42
@@ -11,3 +11,3 @@ | ||
import { OKDTO } from 'src/shared/dto/ok.dto'; | ||
|
||
import * as he from 'he'; | ||
@Controller({ path: 'api/templates', version: '1' }) | ||
@@ -41,3 +41,3 @@ | ||
this.logger.error(err); | ||
res.status(500).send(err); | ||
res.status(500).send(he.escape(err.toString())); | ||
} |
-
Copy modified lines R55-R56
@@ -54,3 +54,4 @@ | ||
"sshpk": "^1.18.0", | ||
"yaml": "^2.7.0" | ||
"yaml": "^2.7.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
||
const password = crypto | ||
.createHmac('sha256', process.env.KUBERO_SESSION_KEY) | ||
.update(pass) |
Check failure
Code scanning / CodeQL
Use of password hash with insufficient computational effort High
an access to password
Password from
an access to password
Password from
an access to password
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 6 days ago
To fix the problem, we need to replace the current password hashing mechanism with a more secure one, such as bcrypt
. This will ensure that the password hashing process is computationally intensive, making it more resistant to brute-force attacks.
- Install the
bcrypt
library if it is not already installed. - Import the
bcrypt
library in theauth.service.ts
file. - Replace the existing SHA-256 hashing code with
bcrypt
hashing. - Update the password comparison logic to use
bcrypt
's comparison function.
-
Copy modified line R14 -
Copy modified lines R37-R38
@@ -13,3 +13,3 @@ | ||
import { JwtService } from '@nestjs/jwt'; | ||
import * as crypto from 'crypto'; | ||
import * as bcrypt from 'bcrypt'; | ||
|
||
@@ -36,7 +36,4 @@ | ||
|
||
const password = crypto | ||
.createHmac('sha256', process.env.KUBERO_SESSION_KEY) | ||
.update(pass) | ||
.digest('hex'); | ||
if (user.password === password) { | ||
const passwordMatch = await bcrypt.compare(pass, user.password); | ||
if (passwordMatch) { | ||
const { password, ...result } = user; |
// decode the base64 encoded URL | ||
const templateUrl = Buffer.from(templateB64, 'base64').toString('ascii'); | ||
|
||
const template = await axios.get(templateUrl).catch((err) => { |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 6 days ago
To fix the SSRF vulnerability, we need to validate and restrict the user input to ensure it only allows safe and intended URLs. One way to achieve this is by using an allow-list of trusted base64 encoded URLs. This approach ensures that only predefined and safe URLs can be used in the axios.get
request.
- Create an allow-list of trusted base64 encoded URLs.
- Validate the
templateB64
parameter against this allow-list before decoding and using it in the request. - If the
templateB64
parameter is not in the allow-list, throw an error.
-
Copy modified lines R8-R12 -
Copy modified lines R16-R20
@@ -7,2 +7,7 @@ | ||
private YAML = require('yaml'); | ||
private readonly allowedTemplates = [ | ||
'aHR0cHM6Ly9leGFtcGxlLmNvbS90ZW1wbGF0ZTE=', // base64 for 'https://example.com/template1' | ||
'aHR0cHM6Ly9leGFtcGxlLmNvbS90ZW1wbGF0ZTI=' // base64 for 'https://example.com/template2' | ||
]; | ||
|
||
constructor() {} | ||
@@ -10,2 +15,7 @@ | ||
async getTemplate(templateB64: string) { | ||
// validate the base64 encoded URL | ||
if (!this.allowedTemplates.includes(templateB64)) { | ||
throw new Error('Invalid template URL'); | ||
} | ||
|
||
// decode the base64 encoded URL |
); | ||
password = crypto | ||
.createHmac('sha256', process.env.KUBERO_SESSION_KEY) | ||
.update(password) |
Check failure
Code scanning / CodeQL
Use of password hash with insufficient computational effort High
an access to password
Password from
an access to password
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 6 days ago
To fix the problem, we should replace the use of crypto.createHmac('sha256', ...)
with a more secure password hashing scheme such as bcrypt
. This will ensure that the password hashing process requires significant computational effort, making it more resistant to brute-force attacks.
The best way to fix the problem without changing existing functionality is to use the bcrypt
library to hash the passwords. We will need to import the bcrypt
library, update the password hashing logic to use bcrypt.hashSync
, and ensure that the salt is properly generated and used.
-
Copy modified line R4 -
Copy modified lines R46-R47
@@ -3,3 +3,3 @@ | ||
dotenv.config(); | ||
import * as crypto from 'crypto'; | ||
import * as bcrypt from 'bcrypt'; | ||
|
||
@@ -45,6 +45,4 @@ | ||
); | ||
password = crypto | ||
.createHmac('sha256', process.env.KUBERO_SESSION_KEY) | ||
.update(password) | ||
.digest('hex'); | ||
const saltRounds = 10; | ||
password = bcrypt.hashSync(password, saltRounds); | ||
} |
Description
Fixes # (issue)
Type of change
How Has This Been Tested?
Test Configuration:
Checklist: