-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semgrep, detect-secrets, and boilerplate code
- Loading branch information
1 parent
8a2e76e
commit ba85f6e
Showing
7 changed files
with
316 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Detect Secrets Scan | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
detect-secrets: | ||
name: Detect Secrets Scan | ||
runs-on: ubuntu-latest | ||
container: | ||
image: python:latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Change Owner of Container Working Directory | ||
run: chown root:root . | ||
- name: Install detect-secrets | ||
run: pip install detect-secrets | ||
- name: Run detect-secrets-hook | ||
shell: bash | ||
run: | | ||
git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline * |
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,41 @@ | ||
name: Semgrep scan | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
env: | ||
configs: "rules/ p/ci p/security-audit p/owasp-top-ten" | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
semgrep: | ||
name: Run Semgrep | ||
runs-on: ubuntu-latest | ||
container: | ||
image: returntocorp/semgrep:1.86 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Fetch the entire history | ||
- name: Mark the Git repository as safe | ||
run: | | ||
git config --global --add safe.directory $GITHUB_WORKSPACE | ||
- name: Fetch all branches and tags | ||
run: | | ||
git fetch --all | ||
git fetch --tags | ||
- name: run semgrep | ||
id: run_semgrep | ||
env: | ||
SEMGREP_RULES: ${{ env.configs }} | ||
SEMGREP_ENABLE_VERSION_CHECK: 0 | ||
SEMGREP_SEND_METRICS: off | ||
shell: bash | ||
run: | | ||
semgrep scan . --error --gitlab-sast -o /tmp/semgrep.json | ||
- name: Show Semgrep report | ||
if: success() || failure() | ||
run: cat /tmp/semgrep.json |
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,24 @@ | ||
repos: | ||
- repo: https://github.com/semgrep/semgrep | ||
rev: '768d0f4c3ccb4b1740eef22bbbd57fc936450df2' # frozen: v1.84.1 | ||
hooks: | ||
- id: semgrep | ||
args: | ||
- --config | ||
- rules/ | ||
- --error | ||
- --skip-unknown-extensions | ||
- --metrics | ||
- 'off' | ||
stages: | ||
- pre-push | ||
- repo: https://github.com/Yelp/detect-secrets | ||
rev: '68e8b45440415753fff70a312ece8da92ba85b4a' # frozen: v1.5.0 | ||
hooks: | ||
- id: detect-secrets | ||
args: | ||
- --baseline | ||
- .secrets.baseline | ||
stages: | ||
- pre-commit | ||
exclude: package-lock.json |
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,133 @@ | ||
{ | ||
"version": "1.5.0", | ||
"plugins_used": [ | ||
{ | ||
"name": "ArtifactoryDetector" | ||
}, | ||
{ | ||
"name": "AWSKeyDetector" | ||
}, | ||
{ | ||
"name": "AzureStorageKeyDetector" | ||
}, | ||
{ | ||
"name": "Base64HighEntropyString", | ||
"limit": 4.5 | ||
}, | ||
{ | ||
"name": "BasicAuthDetector" | ||
}, | ||
{ | ||
"name": "CloudantDetector" | ||
}, | ||
{ | ||
"name": "DiscordBotTokenDetector" | ||
}, | ||
{ | ||
"name": "GitHubTokenDetector" | ||
}, | ||
{ | ||
"name": "HexHighEntropyString", | ||
"limit": 3.0 | ||
}, | ||
{ | ||
"name": "IbmCloudIamDetector" | ||
}, | ||
{ | ||
"name": "IbmCosHmacDetector" | ||
}, | ||
{ | ||
"name": "JwtTokenDetector" | ||
}, | ||
{ | ||
"name": "KeywordDetector", | ||
"keyword_exclude": "" | ||
}, | ||
{ | ||
"name": "MailchimpDetector" | ||
}, | ||
{ | ||
"name": "NpmDetector" | ||
}, | ||
{ | ||
"name": "PrivateKeyDetector" | ||
}, | ||
{ | ||
"name": "SendGridDetector" | ||
}, | ||
{ | ||
"name": "SlackDetector" | ||
}, | ||
{ | ||
"name": "SoftlayerDetector" | ||
}, | ||
{ | ||
"name": "SquareOAuthDetector" | ||
}, | ||
{ | ||
"name": "StripeDetector" | ||
}, | ||
{ | ||
"name": "TwilioKeyDetector" | ||
} | ||
], | ||
"filters_used": [ | ||
{ | ||
"path": "detect_secrets.filters.allowlist.is_line_allowlisted" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.common.is_baseline_file", | ||
"filename": ".secrets.baseline" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", | ||
"min_level": 2 | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_indirect_reference" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_likely_id_string" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_lock_file" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_potential_uuid" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_sequential_string" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_swagger_file" | ||
}, | ||
{ | ||
"path": "detect_secrets.filters.heuristic.is_templated_secret" | ||
} | ||
], | ||
"results": { | ||
".pre-commit-config.yaml": [ | ||
{ | ||
"type": "Hex High Entropy String", | ||
"filename": ".pre-commit-config.yaml", | ||
"hashed_secret": "23414c22063b86dd91d7570689f2da10d72ec4f8", | ||
"is_verified": false, | ||
"line_number": 3 | ||
}, | ||
{ | ||
"type": "Hex High Entropy String", | ||
"filename": ".pre-commit-config.yaml", | ||
"hashed_secret": "86242b7a7b67c1fd83514757a6b319602d648e94", | ||
"is_verified": false, | ||
"line_number": 16 | ||
} | ||
] | ||
}, | ||
"generated_at": "2024-09-23T17:27:01Z" | ||
} |
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,52 @@ | ||
// pages/comments.js | ||
|
||
import { useState, useEffect } from 'react'; | ||
|
||
export default function Comments() { | ||
const [comments, setComments] = useState([]); | ||
const [newComment, setNewComment] = useState(''); | ||
|
||
useEffect(() => { | ||
// Load comments from local storage when the component mounts | ||
const savedComments = JSON.parse(localStorage.getItem('comments')) || []; | ||
setComments(savedComments); | ||
}, []); | ||
|
||
const handleAddComment = () => { | ||
if (newComment.trim() === '') return; | ||
|
||
const updatedComments = [...comments, newComment]; | ||
setComments(updatedComments); | ||
setNewComment(''); | ||
localStorage.setItem('comments', JSON.stringify(updatedComments)); | ||
}; | ||
|
||
const handleRemoveComment = (index) => { | ||
const updatedComments = comments.filter((_, i) => i !== index); | ||
setComments(updatedComments); | ||
localStorage.setItem('comments', JSON.stringify(updatedComments)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Comments</h1> | ||
<div> | ||
<input | ||
type="text" | ||
value={newComment} | ||
onChange={(e) => setNewComment(e.target.value)} | ||
placeholder="Add a comment" | ||
/> | ||
<button onClick={handleAddComment}>Submit</button> | ||
</div> | ||
<ul> | ||
{comments.map((comment, index) => ( | ||
<li key={index}> | ||
{comment} | ||
<button onClick={() => handleRemoveComment(index)}>Remove</button> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} |
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 @@ | ||
rules: | ||
- id: detect-dangerous-innerhtml | ||
pattern: | | ||
<$_ dangerouslySetInnerHTML={ { __html: $VAL } } /> | ||
message: "Usage of 'dangerouslySetInnerHTML' can lead to XSS vulnerabilities. Avoid using it unless absolutely necessary." | ||
severity: ERROR | ||
languages: [javascript, typescript] | ||
metadata: | ||
category: security | ||
technology: react |