-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
933da9f
commit 6c69709
Showing
50 changed files
with
25,942 additions
and
17,879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ jobs: | |
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
pycharm-version: ['2021.2'] | ||
pycharm-version: ['2021.3'] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
@@ -27,7 +27,7 @@ jobs: | |
java-version: 11 | ||
- uses: eskatos/gradle-command-action@v1 | ||
with: | ||
arguments: jacocoTestReport -PintellijPublishToken=FAKE_TOKEN -PintellijVersion=2021.2 | ||
arguments: jacocoTestReport -PintellijPublishToken=FAKE_TOKEN -PintellijVersion=2021.3 | ||
- name: Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package security.helpers | ||
|
||
import com.intellij.codeInspection.LocalInspectionToolSession | ||
import com.jetbrains.python.psi.types.TypeEvalContext | ||
|
||
object TypeEvalContextHelper { | ||
fun getTypeEvalContext(session: LocalInspectionToolSession): TypeEvalContext { | ||
return TypeEvalContext.codeAnalysis(session.file.project, session.file) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package security.packaging | ||
|
||
import com.jetbrains.python.packaging.PyPackage | ||
import io.ktor.client.* | ||
import io.ktor.client.engine.apache.* | ||
import io.ktor.client.features.* | ||
import io.ktor.client.features.json.* | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import kotlinx.coroutines.TimeoutCancellationException | ||
import java.net.SocketTimeoutException | ||
|
||
|
||
class PypiChecker : BasePackageChecker() { | ||
var baseUrl = "https://pypi.org" | ||
|
||
class PyPiIssue (val record: VulnerabilityRecord, pyPackage: PyPackage): PackageIssue(pyPackage = pyPackage) { | ||
override fun getMessage(): String { | ||
return "${record.id} found in ${pyPackage.name} impacting version ${pyPackage.version}. <br/>See <a href='${record.link}'>${record.link}</a> for details" | ||
} | ||
} | ||
|
||
data class VulnerabilityRecord ( | ||
val id: String, | ||
val aliases: List<String>?, | ||
val details: String, | ||
val fixed_in: List<String>?, | ||
val link: String, | ||
val source: String | ||
) | ||
|
||
data class PyPiPackageApiResponse( | ||
val info: Any, | ||
val last_serial: Int, | ||
val releases: Any, | ||
val urls: Any, | ||
val vulnerabilities: List<VulnerabilityRecord>? | ||
) | ||
|
||
private suspend fun load(packageName: String, packageVersion: String): PyPiPackageApiResponse? { | ||
val client = HttpClient(Apache) { | ||
install(JsonFeature) { | ||
serializer = GsonSerializer{ | ||
serializeNulls() | ||
disableHtmlEscaping() | ||
} | ||
} | ||
defaultRequest { | ||
headers { | ||
header("Content-Type", "application/json; charset=utf-8") | ||
} | ||
} | ||
engine { | ||
connectTimeout = 60_000 | ||
connectionRequestTimeout = 60_000 | ||
socketTimeout = 60_000 | ||
} | ||
} | ||
|
||
try { | ||
return client.get<PyPiPackageApiResponse>(Url("$baseUrl/pypi/$packageName/$packageVersion/json")) | ||
} catch (t: TimeoutCancellationException){ | ||
throw PackageCheckerLoadException("Timeout connecting to PyPi API.") | ||
} catch (t: SocketTimeoutException){ | ||
throw PackageCheckerLoadException("Timeout on socket.") | ||
} catch (t: ServerResponseException){ | ||
throw PackageCheckerLoadException("Server error on PyPi API.") | ||
} | ||
} | ||
|
||
override fun hasMatch(pythonPackage: PyPackage?): Boolean { | ||
return true // Hardcode to prevent it being called twice | ||
} | ||
|
||
override suspend fun getMatches (pythonPackage: PyPackage?): List<PyPiIssue> { | ||
if (pythonPackage==null) return listOf() | ||
val records: ArrayList<PyPiIssue> = ArrayList() | ||
val data = load(pythonPackage.name.lowercase(), pythonPackage.version) ?: return records | ||
if (data.vulnerabilities == null) return records | ||
|
||
data.vulnerabilities.forEach { issue -> | ||
records.add(PyPiIssue(issue, pythonPackage)) | ||
} | ||
|
||
return records | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.