Skip to content

JS: add query js/cleartext-logging#73

Merged
semmle-qlci merged 7 commits intomasterfrom
unknown repository
Aug 22, 2018
Merged

JS: add query js/cleartext-logging#73
semmle-qlci merged 7 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Aug 20, 2018

This PR adds a taint analysis query that flags logging of sensitive data in clear text. Logged sensitive data may be stored, so this query is really just a sibling of js/clear-text-storage-of-sensitive-data, they therefore share a qhelp file.

Programmers construct log messages in very different ways, so this query is much more conservative that its sibling. In particular, his query considers "passwords" to be the only source of sensitive data.

Evaluation on our standard benchmarks reveal two true positives, and nothing else.

The performance seems fine for a new security query, here are the numbers for a comparison on the security suite: https://git.semmle.com/gist/esben/3e07f35b8aab1caff35eeab990615d19

@ghost ghost added the JS label Aug 20, 2018
@ghost ghost self-requested a review as a code owner August 20, 2018 06:39
Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! Looks like you put a lot of work into fine-tuning the heuristics.

A few suggestions, but overall the results speak for themselves.


| **Query** | **Tags** | **Purpose** |
|-----------------------------|-----------|--------------------------------------------------------------------|
| Clear text logging of sensitive information (`js/cleartext-logging`) | security, external/cwe/cwe-312, external/cwe/cwe-315, external/cwe/cwe-359 | Highlights logging of sensitive information, indicating a violation of [CWE-312](https://cwe.mitre.org/data/definitions/312.html). Results shown on lgtm by default. |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: "clear-text logging" should probably have a dash between "clear" and "text". Also, upper-case LGTM.

/**
* Holds if `tl` is used in a browser environment.
*/
predicate inBrowserEnvironment(TopLevel tl) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOI, could this lead to false negatives for Electron apps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that is a false negative.
This predicate is used to exclude alerts for logging that occurs on the user's own computer since that is innocent in practice.
Both browsers and electron apps (that use browser features) are run on the user's own computer.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right.

/**
* Holds if `sink` only is reachable in a "test" environment.
*/
predicate inTestEnvironment(Sink sink) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we leave it to our file classification to hide results in test code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not prevent results in test code, it prevents results like this:

if (environment.isTestEnv()) {
  console.log("Password is: " + password); // OK
}

See the test:
https://github.com/Semmle/ql/pull/73/files#diff-48bc5394f61be303fa92728aec0a85a8R92

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. To be honest, though, this predicate doesn't make me very happy. It looks very ad-hoc and brittle. Could we come up with something slightly more rigorous?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the check for now, it does not make a difference on our default benchmarks.

}

private string getAStandardLoggerMethodName() {
// log level names used in RFC5424, `npm`, `console`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn this into qldoc, since we have it anyway?

result = "info" or
result = "log" or
result = "notice" or
result = "silly" or

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.
https://docs.npmjs.com/misc/config#loglevel: "silent", "error", "warn", "notice", "http", "timing", "info", "verbose", "silly"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good. My favourite in this list is actually "http", though. Well done for not including it in this predicate.

@@ -0,0 +1,224 @@
/**
* Provides a dataflow tracking configuration for reasoning about cleartext logging of sensitive information.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/cleartext/clear-text/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And below.

node instanceof Barrier
}

override predicate isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node trg) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates a fair amount of code from the taint tracking library. Please refactor and reuse.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I made the concatenation part of StringManipulationTaintStep public.
Performance of js/cleartext-logging is unchanged, but I will start a sanity check for the ordinary taint queries now.

/**
* An object with a property that may contain password information
*
* This is a source since `toString()` on this object will show the property value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if they have defined a custom toString, otherwise it'll show [object Object].

(
this.asExpr().(VarAccess).getName() = name
or
exists (DataFlow::PropRead read, DataFlow::Node base |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists (DataFlow::SourceNode base |
  this = base.getAPropertyRead(name) and
  // avoid (...)
  not base.getAPropertyWrite(name).getRhs() instanceof NonCleartextPassword
)


ObjectPasswordPropertySource() {
exists (DataFlow::PropWrite write |
write.getPropertyName() = name and

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write = this.(DataFlow::SourceNode).getAWrite(name) and

@xiemaisi
Copy link

xiemaisi commented Aug 20, 2018

@felicity-semmle, who should we request a doc review from? (I can @-mention @Semmle/doc, but can't request a review.)

@mchammer01
Copy link
Contributor

mc-semmle ;-)

@xiemaisi
Copy link

Thanks; unfortunately I cannot request a review from you either (maybe you need to get yourself added to the Semmle organisation or something?).

@mchammer01
Copy link
Contributor

I believe Pavel added me to the Semmle organization and to the docteam. How strange.

@xiemaisi xiemaisi requested a review from mchammer01 August 20, 2018 09:33
@@ -0,0 +1,55 @@
/**
* @name Clear text logging of sensitive information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear-text logging (with an hyphen)?

@@ -0,0 +1,5 @@
<!DOCTYPE qhelp PUBLIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 18: to look up

@ghost
Copy link
Author

ghost commented Aug 21, 2018

All comments addressed.

Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more nit.

@@ -0,0 +1,38 @@
/**
* @name Clear-text logging of sensitive information
* @description Sensitive information logged without encryption or hashing can expose it to an

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description sounds weird to me. Who or what can expose it to an attacker?

Perhaps rephrase as "Logging sensitive information without encryption or hashing (...)".

result = "info" or
result = "log" or
result = "notice" or
result = "silly" or

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good. My favourite in this list is actually "http", though. Well done for not including it in this predicate.

@ghost
Copy link
Author

ghost commented Aug 21, 2018

Removed last nit with an amend.

@semmle-qlci semmle-qlci merged commit 7e7e30c into github:master Aug 22, 2018
aibaars added a commit that referenced this pull request Oct 14, 2021
Update tree-sitter-ruby to pick up improvements to calls
smowton pushed a commit to smowton/codeql that referenced this pull request Dec 6, 2021
erik-krogh pushed a commit to erik-krogh/ql that referenced this pull request Dec 15, 2021
erik-krogh pushed a commit to erik-krogh/ql that referenced this pull request Dec 15, 2021
dbartol pushed a commit that referenced this pull request Dec 18, 2024
fix(controlcheck): Improve checks for actors
MathiasVP pushed a commit to MathiasVP/ql that referenced this pull request Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants