Skip to content

Commit

Permalink
Use simple API base codemod for HTTPS connection
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 17, 2023
1 parent 6df53cc commit 57df277
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions src/core_codemods/https_connection.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from typing import Sequence, Set

import libcst as cst
from libcst.codemod import Codemod, CodemodContext
from libcst.codemod.visitors import AddImportsVisitor, RemoveImportsVisitor
from libcst.metadata import PositionProvider

from codemodder.codemods.base_codemod import (
BaseCodemod,
CodemodMetadata,
ReviewGuidance,
)
from codemodder.codemods.base_codemod import ReviewGuidance
from codemodder.codemods.api import BaseCodemod
from codemodder.codemods.imported_call_modifier import ImportedCallModifier


Expand Down Expand Up @@ -52,26 +48,20 @@ def count_positional_args(self, arglist: Sequence[cst.Arg]) -> int:
return len(arglist)


class HTTPSConnection(BaseCodemod, Codemod):
METADATA = CodemodMetadata(
DESCRIPTION="Enforce HTTPS connection for `urllib3`.",
NAME="https-connection",
REVIEW_GUIDANCE=ReviewGuidance.MERGE_WITHOUT_REVIEW,
REFERENCES=[
{
"url": "https://owasp.org/www-community/vulnerabilities/Insecure_Transport",
"description": "",
},
{
"url": "https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool",
"description": "",
},
],
)
CHANGE_DESCRIPTION = METADATA.DESCRIPTION
SUMMARY = (
"Changes HTTPConnectionPool to HTTPSConnectionPool to Enforce Secure Connection"
)
class HTTPSConnection(BaseCodemod):
SUMMARY = "Enforce HTTPS Connection for `urllib3`"
NAME = "https-connection"
REVIEW_GUIDANCE = ReviewGuidance.MERGE_WITHOUT_REVIEW
REFERENCES = [
{
"url": "https://owasp.org/www-community/vulnerabilities/Insecure_Transport",
"description": "",
},
{
"url": "https://urllib3.readthedocs.io/en/stable/reference/urllib3.connectionpool.html#urllib3.HTTPConnectionPool",
"description": "",
},
]

METADATA_DEPENDENCIES = (PositionProvider,)

Expand All @@ -80,10 +70,6 @@ class HTTPSConnection(BaseCodemod, Codemod):
"urllib3.connectionpool.HTTPConnectionPool",
}

def __init__(self, codemod_context: CodemodContext, *codemod_args):
Codemod.__init__(self, codemod_context)
BaseCodemod.__init__(self, *codemod_args)

def transform_module_impl(self, tree: cst.Module) -> cst.Module:
visitor = HTTPSConnectionModifier(
self.context,
Expand Down

0 comments on commit 57df277

Please sign in to comment.