-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: Add another example the Hardcoded credential help #13501
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
Conversation
|
QHelp previews: javascript/ql/src/Security/CWE-798/HardcodedCredentials.qhelpHard-coded credentialsIncluding unencrypted hard-coded authentication credentials in source code is dangerous because the credentials may be easily discovered. For example, the code may be open source, or it may be leaked or accidentally revealed, making the credentials visible to an attacker. This, in turn, might enable them to gain unauthorized access, or to obtain privileged information. RecommendationRemove hard-coded credentials, such as user names, passwords and certificates, from source code. Instead, place them in configuration files, environment variables or other data stores if necessary. If possible, store configuration files including credential data separately from the source code, in a secure location with restricted access. ExampleThe following code example connects to an HTTP request using an hard-codes authentication header let base64 = require('base-64');
let url = 'http://example.org/auth';
let username = 'user';
let password = 'passwd';
let headers = new Headers();
//headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));
fetch(url, {method:'GET',
headers: headers,
//credentials: 'user:passwd'
})
.then(response => response.json())
.then(json => console.log(json));
//.done();Instead, user name and password can be supplied through the environment variables ExampleThe following code example connects to a Postgres database using the const pg = require("pg");
const client = new pg.Client({
user: "bob",
host: "database.server.com",
database: "mydb",
password: "correct-horse-battery-staple",
port: 3211
});
client.connect();Instead, user name and password can be supplied through the environment variables References
|
|
Could you also add another I know we didn't have that before, but we might as well add that. And why are some of the lines commented out in your example? |
|
QHelp previews: javascript/ql/src/Security/CWE-798/HardcodedCredentials.qhelperrors/warnings: |
|
That's a good point, I have added a NodeJS example. And uncommented those 2 lines 😄 |
|
QHelp previews: javascript/ql/src/Security/CWE-798/HardcodedCredentials.qhelpHard-coded credentialsIncluding unencrypted hard-coded authentication credentials in source code is dangerous because the credentials may be easily discovered. For example, the code may be open source, or it may be leaked or accidentally revealed, making the credentials visible to an attacker. This, in turn, might enable them to gain unauthorized access, or to obtain privileged information. RecommendationRemove hard-coded credentials, such as user names, passwords and certificates, from source code. Instead, place them in configuration files, environment variables or other data stores if necessary. If possible, store configuration files including credential data separately from the source code, in a secure location with restricted access. ExampleThe following code example connects to an HTTP request using an hard-codes authentication header: let base64 = require('base-64');
let url = 'http://example.org/auth';
let username = 'user';
let password = 'passwd';
let headers = new Headers();
headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));
fetch(url, {
method:'GET',
headers: headers
})
.then(response => response.json())
.then(json => console.log(json))
.done();Instead, user name and password can be supplied through the environment variables let base64 = require('base-64');
let url = 'http://example.org/auth';
let username = process.env.USERNAME;
let password = process.env.PASSWORD;
let headers = new Headers();
headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));
fetch(url, {
method:'GET',
headers: headers
})
.then(response => response.json())
.then(json => console.log(json))
.done();ExampleThe following code example connects to a Postgres database using the const pg = require("pg");
const client = new pg.Client({
user: "bob",
host: "database.server.com",
database: "mydb",
password: "correct-horse-battery-staple",
port: 3211
});
client.connect();Instead, user name and password can be supplied through the environment variables References
|
javascript/ql/src/Security/CWE-798/examples/HardcodedCredentialsHttpRequest.js
Outdated
Show resolved
Hide resolved
erik-krogh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A final nit, and then I think this is ready.
Co-authored-by: Erik Krogh Kristensen <erik-krogh@github.com>
For the context, a customer was confused by the
postgresqlconnection example, as the query has detected a hardcoded credential in the HTTP headerAuthorization.The help seems out-of-context for them.
It may be useful to add more example to match the broad detection that query provides