-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add injection and pwn request detection features. (#1)
Add initial Pwn Request and Actions Injection into dev branch.
- Loading branch information
1 parent
5a046c9
commit 08af9f7
Showing
25 changed files
with
1,279 additions
and
153 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
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 @@ | ||
from .cache_manager import CacheManager |
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,99 @@ | ||
from gato.models import Workflow, Repository | ||
|
||
class CacheManager: | ||
""" | ||
Singleton class that manages an in-memory cache. | ||
TODO: Integrate with Redis. | ||
""" | ||
_instance = None | ||
|
||
def __getstate__(self): | ||
state = self.__dict__.copy() | ||
# Remove the unpicklable entries. | ||
state['_instance'] = None | ||
return state | ||
|
||
def __setstate__(self, state): | ||
# Restore instance attributes | ||
self.__dict__.update(state) | ||
# Restore the singleton instance | ||
self._instance = self | ||
|
||
def __new__(cls): | ||
""" | ||
Create a new instance of the class. If an instance already exists, return that instance. | ||
""" | ||
if cls._instance is None: | ||
cls._instance = super(CacheManager, cls).__new__(cls) | ||
cls._instance.repo_wf_lookup = {} | ||
cls._instance.repo_store = {} | ||
cls._instance.workflow_cache = {} | ||
cls._instance.action_cache = {} | ||
return cls._instance | ||
|
||
def get_workflow(self, repo_slug: str, workflow_name: str): | ||
""" | ||
Get a workflow from the in-memory dictionary. | ||
""" | ||
key = f"{repo_slug}:{workflow_name}" | ||
return self.workflow_cache.get(key, None) | ||
|
||
def is_repo_cached(self, repo_slug: str): | ||
""" | ||
Check if a repository is in the in-memory dictionary. | ||
""" | ||
return repo_slug in self.repo_wf_lookup | ||
|
||
def get_workflows(self, repo_slug: str): | ||
""" | ||
Get all workflows for a repository from the in-memory dictionary. | ||
""" | ||
wf_keys = self.repo_wf_lookup.get(repo_slug, None) | ||
if wf_keys: | ||
return [self.workflow_cache[f"{repo_slug}:{key}"] for key in wf_keys] | ||
else: | ||
return set() | ||
|
||
def get_action(self, repo_slug: str, action_path: str): | ||
""" | ||
Get an action from the in-memory dictionary. | ||
""" | ||
key = f"{repo_slug}:{action_path}" | ||
return self.action_cache.get(key, None) | ||
|
||
def set_repository(self, repository: Repository): | ||
""" | ||
Set a repository in the in-memory dictionary. | ||
""" | ||
key = repository.name | ||
self.repo_store[key] = repository | ||
|
||
def get_repository(self, repo_slug: str): | ||
""" | ||
Get a repository from the in-memory dictionary. | ||
""" | ||
return self.repo_store.get(repo_slug, None) | ||
|
||
def set_workflow(self, repo_slug: str, workflow_name: str, value: Workflow): | ||
""" | ||
Set a workflow in the in-memory dictionary. | ||
""" | ||
key = f"{repo_slug}:{workflow_name}" | ||
if repo_slug not in self.repo_wf_lookup: | ||
self.repo_wf_lookup[repo_slug] = set() | ||
self.repo_wf_lookup[repo_slug].add(workflow_name) | ||
self.workflow_cache[key] = value | ||
|
||
def set_empty(self, repo_slug: str): | ||
""" | ||
Set an empty value in the in-memory dictionary for a repository. | ||
""" | ||
self.repo_wf_lookup[repo_slug] = set() | ||
|
||
def set_action(self, repo_slug: str, action_path: str, value: str): | ||
""" | ||
Set an action in the in-memory dictionary. | ||
""" | ||
key = f"{repo_slug}:{action_path}" | ||
self.action_cache[key] = value |
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 @@ | ||
from .configuration_manager import ConfigurationManager |
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,67 @@ | ||
import json | ||
import os | ||
import glob | ||
|
||
class ConfigurationManager: | ||
""" | ||
A singleton class to manage configuration data. | ||
Attributes: | ||
_instance (ConfigurationManager): The singleton instance of the ConfigurationManager class. | ||
_config (dict): The loaded configuration data. | ||
""" | ||
|
||
_instance = None | ||
_config = None | ||
|
||
def __new__(cls, *args, **kwargs): | ||
""" | ||
Overrides the default object creation behavior to implement the singleton pattern. | ||
Returns: | ||
ConfigurationManager: The singleton instance of the ConfigurationManager class. | ||
""" | ||
if cls._instance is None: | ||
cls._instance = super(ConfigurationManager, cls).__new__(cls, *args, **kwargs) | ||
return cls._instance | ||
|
||
def __init__(self): | ||
""" | ||
Initializes the ConfigurationManager instance by loading all JSON files in the script directory. | ||
""" | ||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
json_files = glob.glob(os.path.join(script_dir, '*.json')) | ||
for file_path in json_files: | ||
self.load(file_path) | ||
|
||
def load(self, file_path): | ||
""" | ||
Loads a JSON file and merges its entries into the existing configuration data. | ||
Args: | ||
file_path (str): The path to the JSON file to load. | ||
""" | ||
with open(file_path, 'r') as f: | ||
config = json.load(f) | ||
if self._config is None: | ||
self._config = config | ||
else: | ||
self._config['entries'].update(config['entries']) | ||
|
||
def __getattr__(self, name): | ||
""" | ||
Overrides the default attribute access behavior. If the attribute name matches the 'name' field in the configuration data, it returns the 'entries' field. Otherwise, it raises an AttributeError. | ||
Args: | ||
name (str): The name of the attribute to access. | ||
Returns: | ||
dict: The 'entries' field of the configuration data if the attribute name matches the 'name' field. | ||
Raises: | ||
AttributeError: If the attribute name does not match the 'name' field in the configuration data. | ||
""" | ||
if self._config and name == self._config['name']: | ||
return self._config['entries'] | ||
else: | ||
raise AttributeError(f"'ConfigurationManager' object has no attribute '{name}'") |
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,49 @@ | ||
{ | ||
"name": "WORKFLOW_PARSING", | ||
"entries": { | ||
"PERMISSION_CHECK_ACTIONS": [ | ||
"check-actor-permission" | ||
], | ||
"SAFE_IF_CHECKS": [ | ||
"github.event.pull_request.merged == true", | ||
"== labeled", | ||
"== 'labeled'", | ||
"github.event.pull_request.head.repo.fork != true" | ||
], | ||
"GITHUB_HOSTED_LABELS": [ | ||
"ubuntu-latest", | ||
"macos-latest", | ||
"macOS-latest", | ||
"windows-latest", | ||
"ubuntu-18.04", | ||
"ubuntu-20.04", | ||
"ubuntu-22.04", | ||
"windows-2022", | ||
"windows-2019", | ||
"windows-2016", | ||
"macOS-13", | ||
"macOS-12", | ||
"macOS-11", | ||
"macos-11", | ||
"macos-12", | ||
"macos-13", | ||
"macos-13-xl", | ||
"macos-12" | ||
], | ||
"UNSAFE_CONTEXTS": [ | ||
"github.event.issue.title", | ||
"github.event.issue.body", | ||
"github.event.pull_request.title", | ||
"github.event.pull_request.body", | ||
"github.event.comment.body", | ||
"github.event.review.body", | ||
"github.event.head_commit.message", | ||
"github.event.head_commit.author.email", | ||
"github.event.head_commit.author.name", | ||
"github.event.pull_request.head.ref", | ||
"github.event.pull_request.head.label", | ||
"github.event.pull_request.head.repo.default_branch", | ||
"github.head_ref" | ||
] | ||
} | ||
} |
Oops, something went wrong.