Skip to content

Commit 80da48e

Browse files
committed
python: revert last two commits which intended for another branch.
1 parent 7d7b67e commit 80da48e

File tree

3 files changed

+7
-149
lines changed

3 files changed

+7
-149
lines changed

python/ql/lib/semmle/python/Concepts.qll

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -443,41 +443,6 @@ module RegexExecution {
443443
}
444444
}
445445

446-
/**
447-
* A data-flow node that executes an LDAP query.
448-
*
449-
* Extend this class to refine existing API models. If you want to model new APIs,
450-
* extend `LDAPQuery::Range` instead.
451-
*/
452-
class LdapExecution extends DataFlow::Node {
453-
LdapExecution::Range range;
454-
455-
LdapExecution() { this = range }
456-
457-
/** Gets the argument containing the filter string. */
458-
DataFlow::Node getFilter() { result = range.getFilter() }
459-
460-
/** Gets the argument containing the base DN. */
461-
DataFlow::Node getBaseDn() { result = range.getBaseDn() }
462-
}
463-
464-
/** Provides classes for modeling new LDAP query execution-related APIs. */
465-
module LdapExecution {
466-
/**
467-
* A data-flow node that executes an LDAP query.
468-
*
469-
* Extend this class to model new APIs. If you want to refine existing API models,
470-
* extend `LDAPQuery` instead.
471-
*/
472-
abstract class Range extends DataFlow::Node {
473-
/** Gets the argument containing the filter string. */
474-
abstract DataFlow::Node getFilter();
475-
476-
/** Gets the argument containing the base DN. */
477-
abstract DataFlow::Node getBaseDn();
478-
}
479-
}
480-
481446
/**
482447
* A data-flow node that escapes meta-characters, which could be used to prevent
483448
* injection attacks.
@@ -535,20 +500,8 @@ module Escaping {
535500
/** Gets the escape-kind for escaping a string so it can safely be included in HTML. */
536501
string getHtmlKind() { result = "html" }
537502

538-
/** Gets the escape-kind for escaping a string so it can safely be included in a regular expression. */
503+
/** Gets the escape-kind for escaping a string so it can safely be included in HTML. */
539504
string getRegexKind() { result = "regex" }
540-
541-
/**
542-
* Gets the escape-kind for escaping a string so it can safely be used as a
543-
* distinguished name (DN) in an LDAP search.
544-
*/
545-
string getLdapDnKind() { result = "ldap_dn" }
546-
547-
/**
548-
* Gets the escape-kind for escaping a string so it can safely be used as a
549-
* filter in an LDAP search.
550-
*/
551-
string getLdapFilterKind() { result = "ldap_filter" }
552505
// TODO: If adding an XML kind, update the modeling of the `MarkupSafe` PyPI package.
553506
//
554507
// Technically it claims to escape for both HTML and XML, but for now we don't have
@@ -573,21 +526,6 @@ class RegexEscaping extends Escaping {
573526
RegexEscaping() { range.getKind() = Escaping::getRegexKind() }
574527
}
575528

576-
/**
577-
* An escape of a string so it can be safely used as a distinguished name (DN)
578-
* in an LDAP search.
579-
*/
580-
class LdapDnEscaping extends Escaping {
581-
LdapDnEscaping() { range.getKind() = Escaping::getLdapDnKind() }
582-
}
583-
584-
/**
585-
* An escape of a string so it can be safely used as a filter in an LDAP search.
586-
*/
587-
class LdapFilterEscaping extends Escaping {
588-
LdapFilterEscaping() { range.getKind() = Escaping::getLdapFilterKind() }
589-
}
590-
591529
/** Provides classes for modeling HTTP-related APIs. */
592530
module HTTP {
593531
import semmle.python.web.HttpConstants

python/ql/lib/semmle/python/frameworks/Ldap.qll

Lines changed: 0 additions & 80 deletions
This file was deleted.

python/ql/src/experimental/Security/CWE-090/LDAPInjection.qhelp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
<qhelp>
55
<overview>
66
<p>If an LDAP query or DN is built using string concatenation or string formatting, and the
7-
components of the concatenation include user input without any proper sanitization, a user
7+
components of the concatenation include user input without any proper sanitization, a user
88
is likely to be able to run malicious LDAP queries.</p>
99
</overview>
1010

1111
<recommendation>
1212
<p>If user input must be included in an LDAP query or DN, it should be escaped to
1313
avoid a malicious user providing special characters that change the meaning
14-
of the query. In Python2, user input should be escaped with <code>ldap.dn.escape_dn_chars</code>
15-
or <code>ldap.filter.escape_filter_chars</code>, while in Python3, user input should be escaped with
14+
of the query. In Python2, user input should be escaped with <code>ldap.dn.escape_dn_chars</code>
15+
or <code>ldap.filter.escape_filter_chars</code>, while in Python3, user input should be escaped with
1616
<code>ldap3.utils.dn.escape_rdn</code> or <code>ldap3.utils.conv.escape_filter_chars</code>
17-
depending on the component tainted by the user. A good practice is to escape filter characters
17+
depending on the component tainted by the user. A good practice is to escape filter characters
1818
that could change the meaning of the query (https://tools.ietf.org/search/rfc4515#section-3).</p>
1919
</recommendation>
2020

2121
<example>
22-
<p>In the following examples, the code accepts both <code>username</code> and <code>dc</code> from the user,
22+
<p>In the following examples, the code accepts both <code>username</code> and <code>dc</code> from the user,
2323
which it then uses to build a LDAP query and DN.</p>
2424

2525
<p>The first and the second example uses the unsanitized user input directly
@@ -30,7 +30,7 @@ components, and search for a completely different set of values.</p>
3030
<sample src="examples/example_bad1.py" />
3131
<sample src="examples/example_bad2.py" />
3232

33-
<p>In the third and fourth example, the input provided by the user is sanitized before it is included in the search filter or DN.
33+
<p>In the third and four example, the input provided by the user is sanitized before it is included in the search filter or DN.
3434
This ensures the meaning of the query cannot be changed by a malicious user.</p>
3535

3636
<sample src="examples/example_good1.py" />

0 commit comments

Comments
 (0)