Skip to content

Commit 6c69709

Browse files
authored
OSV integration and updates to safety (#305)
* OSV integration and updates to safety * Updates for new APIs * Annotate 2022 support * Upgrade to the official mockito-kotlin package * API update
1 parent 933da9f commit 6c69709

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+25942
-17879
lines changed

.github/actions/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM anthonypjshaw/pycharm-security:latest
22
COPY action.sh /action.sh
33
COPY parse.py /code/parse.py
44
COPY project.iml /code/project.iml
5-
COPY jdk.table.xml /root/.config/JetBrains/PyCharm2021.2/jdk.table.xml
5+
COPY jdk.table.xml /root/.config/JetBrains/PyCharm2021.3/jdk.table.xml
66
RUN apt-get -y update && apt-get -y install python3 python3-pip python3-venv && python3 -m pip install setuptools
77
RUN ["chmod", "+x", "/action.sh"]
88
ENTRYPOINT ["/action.sh"]

.github/actions/jdk.table.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<root url="file:///usr/lib/python3.6/lib-dynload" type="simple" />
1313
<root url="file:///usr/local/lib/python3.6/dist-packages" type="simple" />
1414
<root url="file:///usr/lib/python3/dist-packages" type="simple" />
15-
<root url="file://$USER_HOME$/Library/Caches/JetBrains/PyCharm2021.2/python_stubs/-1506223722" type="simple" />
15+
<root url="file://$USER_HOME$/Library/Caches/JetBrains/PyCharm2021.3/python_stubs/-1506223722" type="simple" />
1616
<root url="file://$APPLICATION_HOME_DIR$/plugins/python/helpers/python-skeletons" type="simple" />
1717
<root url="file://$APPLICATION_HOME_DIR$/plugins/python/helpers/typeshed/stdlib/3.6" type="simple" />
1818
<root url="file://$APPLICATION_HOME_DIR$/plugins/python/helpers/typeshed/stdlib/3" type="simple" />

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest, macos-latest, windows-latest]
10-
pycharm-version: ['2021.2']
10+
pycharm-version: ['2021.3']
1111
runs-on: ${{ matrix.os }}
1212
steps:
1313
- uses: actions/checkout@v1
@@ -27,7 +27,7 @@ jobs:
2727
java-version: 11
2828
- uses: eskatos/gradle-command-action@v1
2929
with:
30-
arguments: jacocoTestReport -PintellijPublishToken=FAKE_TOKEN -PintellijVersion=2021.2
30+
arguments: jacocoTestReport -PintellijPublishToken=FAKE_TOKEN -PintellijVersion=2021.3
3131
- name: Codecov
3232
uses: codecov/[email protected]
3333
with:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PYCHARM_VERSION=2021.2
1+
ARG PYCHARM_VERSION=2021.3
22
FROM ubuntu:18.04
33
ARG PYCHARM_VERSION
44
RUN echo "Building PyCharm $PYCHARM_VERSION with python-security"

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.25.0
4+
5+
* Added a PyPi API option for package security checking that uses the new PyPI vulnerability API
6+
* Support for 2021.3
7+
* Update safety DB to december
8+
39
## 1.24.3
410

511
* Update safety db to october 2021

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ This plugin will check the installed packages in your Python projects against th
4242

4343
![](doc/_static/safetydb-screenshot.png)
4444

45+
## PyPi vulnerability API
46+
47+
This plugin will check the installed packages in your Python projects against the OSV database in PyPi and raise a warning for any vulnerabilities.
48+
4549
## Current checks
4650

4751
See [Supported Checks](https://pycharm-security.readthedocs.io/en/latest/checks/index.html) for a current list.

build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group 'org.tonybaloney.security'
10-
version '1.24.3'
10+
version '1.25.0'
1111

1212
def ktor_version = "1.6.6"
1313
def kotlin_version = "1.6.0"
@@ -21,9 +21,9 @@ repositories {
2121

2222
dependencies {
2323
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.8.2'
24-
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
25-
testImplementation "net.bytebuddy:byte-buddy:1.12.2"
26-
testImplementation "net.bytebuddy:byte-buddy-agent:1.12.2"
24+
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
25+
testImplementation 'net.bytebuddy:byte-buddy:1.12.2'
26+
testImplementation 'net.bytebuddy:byte-buddy-agent:1.12.2'
2727
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2828
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
2929
compile "io.ktor:ktor-client-core:$ktor_version"
@@ -39,7 +39,7 @@ test {
3939

4040
// See https://github.com/JetBrains/gradle-intellij-plugin/
4141
// Make the intellij version overridable on the command line to support multiple build versions..
42-
def intellijversion = project.hasProperty('intellijVersion') ? project.getProperty('intellijVersion') : '2021.2'
42+
def intellijversion = project.hasProperty('intellijVersion') ? project.getProperty('intellijVersion') : '2021.3'
4343

4444
intellij {
4545
type = 'PC'
@@ -50,9 +50,11 @@ intellij {
5050

5151
patchPluginXml {
5252
changeNotes = """
53-
<h2>1.24.3</h2>
53+
<h2>1.25.0</h2>
5454
<ul>
55-
<li>Safety db update</li>
55+
<li>Added a PyPi API option for package security checking that uses the new PyPI vulnerability API</li>
56+
<li>Support for 2021.3</li>
57+
<li>Update safety DB to december </li>
5658
</ul>
5759
"""
5860
}

src/main/java/security/fixes/FixUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import com.jetbrains.python.psi.*
88

99

1010
fun getPyExpressionAtCaret(file: PsiFile, editor: Editor): PyExpression? {
11-
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyExpression::class.java) ?: return null
11+
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyExpression::class.java)
1212
}
1313

1414
fun getPyCallExpressionAtCaret(file: PsiFile, editor: Editor): PyCallExpression? {
15-
return PsiTreeUtil.getTopmostParentOfType(file.findElementAt(editor.caretModel.offset), PyCallExpression::class.java) ?: return null
15+
return PsiTreeUtil.getTopmostParentOfType(file.findElementAt(editor.caretModel.offset), PyCallExpression::class.java)
1616
}
1717

1818
fun getListLiteralExpressionAtCaret(file: PsiFile, editor: Editor): PyListLiteralExpression? {
19-
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyListLiteralExpression::class.java) ?: return null
19+
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyListLiteralExpression::class.java)
2020
}
2121

2222
fun getBinaryExpressionElementAtCaret(file: PsiFile, editor: Editor): PyBinaryExpression? {
23-
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyBinaryExpression::class.java) ?: return null
23+
return PsiTreeUtil.getParentOfType(file.findElementAt(editor.caretModel.offset), PyBinaryExpression::class.java)
2424
}
2525

2626
fun getNewCallExpressiontAtCaret(file: PsiFile, editor: Editor, project: Project, old: String, new: String): PyCallExpression ? {

src/main/java/security/fixes/ShellEscapeFixer.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiElement
1111
import com.intellij.psi.PsiFile
1212
import com.intellij.util.IncorrectOperationException
1313
import com.jetbrains.python.psi.*
14+
import com.jetbrains.python.psi.types.TypeEvalContext
1415
import security.helpers.QualifiedNameHelpers.getQualifiedName
1516

1617

@@ -56,11 +57,11 @@ class ShellEscapeFixer : LocalQuickFix, IntentionAction, HighPriorityAction {
5657
val list = elementGenerator.createListLiteral()
5758
for (item in oldElement.elements){
5859
if (item is PyReferenceExpression){
59-
list.add(getNewEscapedExpression(file, project, item) as @org.jetbrains.annotations.NotNull PsiElement)
60+
list.add(getNewEscapedExpression(file, project, item) as PsiElement)
6061
continue
6162
} else if (item is PyCallExpression) {
62-
if (getQualifiedName(item) != "shlex.quote") {
63-
list.add(getNewEscapedExpression(file, project, item) as @org.jetbrains.annotations.NotNull PsiElement)
63+
if (getQualifiedName(item, TypeEvalContext.codeAnalysis(project, file)) != "shlex.quote") {
64+
list.add(getNewEscapedExpression(file, project, item) as PsiElement)
6465
continue
6566
}
6667
}

src/main/java/security/helpers/InspectionVisitorExtensions.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ package security.helpers
33
import com.intellij.codeInspection.LocalInspectionToolSession
44
import com.intellij.codeInspection.ProblemsHolder
55
import com.jetbrains.python.inspections.PyInspectionVisitor
6+
import com.jetbrains.python.psi.types.TypeEvalContext
7+
import security.helpers.TypeEvalContextHelper.getTypeEvalContext
68

79

8-
open class SecurityVisitor(holder: ProblemsHolder, session: LocalInspectionToolSession) : PyInspectionVisitor(holder, session) {
10+
open class SecurityVisitor(holder: ProblemsHolder, val session: LocalInspectionToolSession) : PyInspectionVisitor(holder, getTypeEvalContext(session)) {
911
override fun getHolder(): ProblemsHolder {
1012
return super.getHolder()!!
1113
}
14+
15+
val typeEvalContext: TypeEvalContext
16+
get() {
17+
return getTypeEvalContext(session)
18+
}
1219
}

0 commit comments

Comments
 (0)