-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create JavaScript file #12
base: master
Are you sure you want to change the base?
Conversation
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
…gzhang.github.io into feature/separate_DOM
var now = moment().format('MMMM Do YYYY, h:mm:ss a'); | ||
$('#demo').text('Current time: ' + now); | ||
$('#greetButton').on('click', greetUser); | ||
$('#savePasswordButton').on('click', function() { |
Check failure
Code scanning / ESLint
Enforce consistent spacing before `function` definition opening parenthesis Error
|
||
export function greetUser () { | ||
var name = document.getElementById('userInput').value; | ||
if (name == "") { |
Check failure
Code scanning / ESLint
Require the use of `===` and `!==` Error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month ago
To fix the problem, we need to replace the ==
operator with the ===
operator on line 19. This ensures that the comparison checks both the value and the type, preventing any unintended type coercion.
- Locate the comparison on line 19 in the
greetUser
function. - Replace
==
with===
.
No additional methods, imports, or definitions are needed to implement this change.
-
Copy modified line R19
@@ -18,3 +18,3 @@ | ||
var name = document.getElementById('userInput').value; | ||
if (name == "") { | ||
if (name === "") { | ||
name = "guest"; |
<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.6.2/axios.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
}); | ||
}); | ||
|
||
export function greetUser () { |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month ago
To fix this issue, we need to ensure that the user input is properly escaped before being inserted into the DOM. Instead of using innerHTML
, we should use textContent
to avoid interpreting the input as HTML. This will ensure that any HTML characters in the user input are treated as text and not as HTML.
- Replace the use of
innerHTML
withtextContent
for setting the greeting message. - This change should be made on line 22 of the provided code.
-
Copy modified line R22
@@ -21,3 +21,3 @@ | ||
} | ||
document.getElementById('greeting').innerHTML = 'Hello, ' + name + '!'; | ||
document.getElementById('greeting').textContent = 'Hello, ' + name + '!'; | ||
} |
if (name == "") { | ||
name = "guest"; | ||
} | ||
document.getElementById('greeting').innerHTML = 'Hello, ' + name + '!'; |
Check failure
Code scanning / CodeQL
Clear text storage of sensitive information High
an access to password
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 1 month ago
To fix the problem, we need to ensure that the password is encrypted before being stored in localStorage. We can use the Node.js crypto
module to encrypt the password. This will involve creating an encryption function and using it to encrypt the password before storing it. Additionally, we should avoid displaying the password in clear text in the DOM.
-
Copy modified line R5 -
Copy modified lines R28-R30 -
Copy modified lines R36-R40
@@ -4,2 +4,3 @@ | ||
const axios = window.axios; | ||
const crypto = window.crypto || require('crypto'); | ||
|
||
@@ -26,4 +27,5 @@ | ||
if (_.isEmpty(username) || _.isEmpty(password)) return; | ||
localStorage.setItem(username, password); | ||
$('#demo').text('Username: ' + username + ', Password: ' + password); | ||
const encryptedPassword = encrypt(password); | ||
localStorage.setItem(username, encryptedPassword); | ||
$('#demo').text('Username: ' + username + ', Password: [encrypted]'); | ||
} | ||
@@ -33,2 +35,7 @@ | ||
} | ||
|
||
function encrypt(text) { | ||
const cipher = crypto.createCipher('aes-256-ctr', 'password'); | ||
return cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); | ||
} | ||
|
$('#demo').text('Username: ' + username + ', Password: ' + password); | ||
} | ||
|
||
export function processData (data){ |
Check failure
Code scanning / CodeQL
Hard-coded credentials Critical
This pull request includes several changes to improve the project structure, update dependencies, and enhance the functionality of the application. The most important changes include updating external libraries, separating DOM manipulation logic into a new file, and adding ESLint configuration.