-
Notifications
You must be signed in to change notification settings - Fork 4
Add a security scan and use /validate and /security comment triggers #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghutchis
wants to merge
4
commits into
master
Choose a base branch
from
add-security-workflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5178c98
Add a security scan and use /validate and /security comment triggers
ghutchis e58b81d
Some cleanups, including moving bits to a helper script
ghutchis db80da6
Based on code review, make sure to only update one entry
ghutchis 0570a68
Apply suggestions from code review
ghutchis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,162 @@ | ||
| rules: | ||
| # ── Code execution / injection ── | ||
| - id: avogadro-eval-exec | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: eval(...) | ||
| - pattern: exec(...) | ||
| - pattern: compile(..., ..., "exec") | ||
| message: > | ||
| eval()/exec()/compile() found. These allow arbitrary code execution | ||
| and are almost never needed in Avogadro plugins. Use structured data | ||
| processing (JSON, etc.) instead. | ||
| severity: ERROR | ||
| languages: [python] | ||
|
|
||
| - id: avogadro-dynamic-import | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: __import__(...) | ||
| - pattern: importlib.import_module(...) | ||
| message: > | ||
| Dynamic import detected. Plugins should use standard imports. | ||
| If loading optional dependencies, use try/except around normal imports. | ||
| severity: WARNING | ||
| languages: [python] | ||
|
|
||
| # ── Deserialization ── | ||
| - id: avogadro-unsafe-deserialization | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: pickle.load(...) | ||
| - pattern: pickle.loads(...) | ||
| - pattern: _pickle.load(...) | ||
| - pattern: marshal.load(...) | ||
| - pattern: marshal.loads(...) | ||
| - patterns: | ||
| - pattern: yaml.load(...) | ||
| - pattern-not: yaml.load(..., Loader=yaml.SafeLoader, ...) | ||
| - pattern-not: yaml.load(..., Loader=SafeLoader, ...) | ||
| - pattern: shelve.open(...) | ||
| message: > | ||
| Unsafe deserialization can execute arbitrary code. Use JSON or | ||
| other safe formats. If YAML is needed, use yaml.safe_load(). | ||
| severity: ERROR | ||
| languages: [python] | ||
|
|
||
| # ── Subprocess calls ── | ||
| - id: avogadro-subprocess-shell | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: subprocess.call(..., shell=True, ...) | ||
| - pattern: subprocess.run(..., shell=True, ...) | ||
| - pattern: subprocess.Popen(..., shell=True, ...) | ||
| - pattern: os.system(...) | ||
| - pattern: os.popen(...) | ||
| message: > | ||
| Shell command execution detected. Prefer subprocess with shell=False | ||
| and explicit argument lists. os.system() and os.popen() should never | ||
| be used. | ||
| severity: ERROR | ||
| languages: [python] | ||
|
|
||
| - id: avogadro-subprocess-review | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: subprocess.call(...) | ||
| - pattern: subprocess.run(...) | ||
| - pattern: subprocess.Popen(...) | ||
| - pattern: subprocess.check_output(...) | ||
| - pattern: subprocess.check_call(...) | ||
| message: > | ||
| Subprocess call detected. This is often legitimate for plugins that | ||
| wrap external tools (ORCA, Gaussian, xtb, etc.), but verify the | ||
| command is not constructed from untrusted input. | ||
| severity: WARNING | ||
| languages: [python] | ||
|
|
||
| # ── Network access ── | ||
| - id: avogadro-network-access | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: requests.get(...) | ||
| - pattern: requests.post(...) | ||
| - pattern: requests.put(...) | ||
| - pattern: requests.delete(...) | ||
| - pattern: urllib.request.urlopen(...) | ||
| - pattern: http.client.HTTPConnection(...) | ||
| - pattern: http.client.HTTPSConnection(...) | ||
| - pattern: socket.socket(...) | ||
| message: > | ||
| Network access detected. Verify the plugin genuinely needs network | ||
| access and that URLs are not constructed from untrusted input. | ||
| severity: WARNING | ||
| languages: [python] | ||
|
|
||
| # ── File system operations ── | ||
| - id: avogadro-dangerous-file-ops | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: shutil.rmtree(...) | ||
| - pattern: os.removedirs(...) | ||
| - pattern: pathlib.Path(...).unlink(...) | ||
| message: > | ||
| Destructive file operations detected. Verify paths are restricted | ||
| to the plugin's working directory. | ||
| severity: WARNING | ||
| languages: [python] | ||
|
|
||
| - id: avogadro-path-traversal | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: open($PATH + ..., ...) | ||
| - pattern: open(f"...{$VAR}...", ...) | ||
| - pattern: os.path.join(..., $USER_INPUT, ...) | ||
| message: > | ||
| Possible path traversal — file paths should be validated to prevent | ||
| accessing files outside the intended directory. | ||
| severity: WARNING | ||
| languages: [python] | ||
|
|
||
| # ── Credentials and secrets ── | ||
| - id: avogadro-hardcoded-secret | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: $VAR = "sk-..." | ||
| - pattern: $VAR = "api_key_..." | ||
| - pattern: | | ||
| password = "..." | ||
| - pattern: | | ||
| token = "..." | ||
| - pattern: | | ||
| secret = "..." | ||
| - pattern: | | ||
| api_key = "..." | ||
| message: > | ||
| Possible hardcoded credential. Use environment variables or | ||
| Avogadro's configuration system for secrets. | ||
| severity: ERROR | ||
| languages: [python] | ||
|
|
||
| # ── Native code / FFI ── | ||
| - id: avogadro-native-code | ||
| patterns: | ||
| - pattern-either: | ||
| - pattern: ctypes.cdll.LoadLibrary(...) | ||
| - pattern: ctypes.CDLL(...) | ||
| - pattern: cffi.FFI() | ||
| message: > | ||
| Native code loading via ctypes/cffi. This bypasses Python's safety | ||
| features and requires careful review. | ||
| severity: ERROR | ||
| languages: [python] | ||
|
|
||
| # ── Avogadro-specific best practices ── | ||
| - id: avogadro-stderr-for-progress | ||
| patterns: | ||
| - pattern: print(...) # in the context of a plugin script | ||
| message: > | ||
| Avogadro plugin scripts communicate via stdout (JSON). Use | ||
| sys.stderr.write() for progress messages, not print(). | ||
| severity: INFO | ||
| languages: [python] | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.