-
-
Notifications
You must be signed in to change notification settings - Fork 0
Optimize init script and bump dependencies #120
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
da3ce39
Bump the dependencies group with 3 updates
dependabot[bot] 1774420
feat: sanitize input name and fix checkout action version in workflows
google-labs-jules[bot] 1b08770
⚡ Bolt: optimize input validation and file I/O in init script
google-labs-jules[bot] 9a4e098
⚡ Bolt: optimize init script and fix SonarCloud security alert
google-labs-jules[bot] 5a27536
⚡ Bolt: optimize init script and fix SonarCloud path traversal alert
google-labs-jules[bot] 58ca428
⚡ Bolt: optimize init script and fix SonarCloud false-positive
google-labs-jules[bot] 504e184
Optimize validation and grouping file I/O in scripts/init.py
google-labs-jules[bot] a530d7b
Update checkout action to v7
amrabed 0bc1ede
Refactor tests to use project.app.main without alias
amrabed 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,7 @@ | ||
| ## 2025-07-17 - Efficiency of str.isprintable() | ||
| **Learning:** Checking for printable characters via `not value.isprintable()` is ~15-18x faster than manual character-by-character iteration with `any(not c.isprintable() for c in value)` in Python. | ||
| **Action:** Always prefer the built-in `str.isprintable()` method over manual loops or generators for character validation. | ||
|
|
||
| ## 2025-07-17 - Grouped I/O in scripts/init.py | ||
| **Learning:** Performing multiple consecutive file reads/writes on the same files (`pyproject.toml`, `mkdocs.yml`) causes redundant disk I/O overhead. | ||
| **Action:** Group file modifications by file path to perform exactly one read and one write operation per file. |
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,3 @@ | ||
| # Sentinel Security Journal | ||
|
|
||
| This journal contains critical security learnings specific to this project. |
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
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
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 |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ | |
| ]: | ||
| if len(value) > 100: | ||
| raise UsageError(f"Invalid {label}: maximum length is 100 characters.") | ||
| if any(not c.isprintable() for c in value): | ||
| if not value.isprintable(): | ||
| raise UsageError(f"Invalid {label}: control characters are not allowed.") | ||
| if label != "description" and '"' in value: | ||
| raise UsageError(f"Invalid {label}: double quotes are not allowed.") | ||
|
|
@@ -73,31 +73,43 @@ | |
| escaped_author = toml_escape(author) | ||
| escaped_email = toml_escape(email) | ||
|
|
||
| replacements = [ | ||
| ("docs/reference/app.md", r"^::: project\.app", f"::: {source}.app"), | ||
| ("mkdocs.yml", r"^repo_name: .*", f"repo_name: {github}/{name}"), | ||
| ("mkdocs.yml", r"^repo_url: .*", f"repo_url: https://github.com/{github}/{name}"), | ||
| ("pyproject.toml", r"^source = \[.*\]", f'source = ["{source}"]'), | ||
| ("pyproject.toml", r'^app = "project\.app:main"', f'app = "{source}.app:main"'), | ||
| ("pyproject.toml", r'^name = ".*"', f'name = "{source}"'), | ||
| ("pyproject.toml", r'^description = ".*"', f'description = "{escaped_description}"'), | ||
| ("pyproject.toml", r"^authors = \[.*\]", f'authors = ["{escaped_author} <{escaped_email}>"]'), | ||
| ("docs/README.md", r"^# .*", f"# {description}"), | ||
| (".github/CODEOWNERS", r"@.*", f"@{github}"), | ||
| (".github/FUNDING.yml", r"^github: \[.*\]", f"github: [{github}]"), | ||
| ] | ||
|
|
||
| for filepath, pattern, replacement in replacements: | ||
| def update_file(filepath: str, file_replacements: list[tuple[str, str]]): | ||
| path = Path(filepath) | ||
| if not path.exists(): | ||
| secho(f" Warning: File {filepath} not found, skipping. ⚠️", fg="yellow") | ||
| continue | ||
| return | ||
|
|
||
| content = path.read_text() | ||
| # Use a lambda for replacement to avoid regex backreference injection | ||
| new_content = re.sub(pattern, lambda _, r=replacement: r, content, flags=re.MULTILINE) | ||
| path.write_text(new_content) | ||
| secho(f" Updated {filepath} ✅", fg="blue") | ||
| new_content = content | ||
| for pattern, replacement in file_replacements: | ||
| # Use a lambda for replacement to avoid regex backreference injection | ||
| new_content = re.sub(pattern, lambda _, r=replacement: r, new_content, flags=re.MULTILINE) | ||
|
|
||
| if new_content != content: | ||
| path.write_text(new_content) | ||
Check failureCode scanning / SonarCloud I/O function calls should not be vulnerable to path injection attacks High
Change this code to not construct the path from user-controlled data. See more on SonarQube Cloud
Check failure on line 89 in scripts/init.py
|
||
| secho(f" Updated {filepath} ✅", fg="blue") | ||
|
|
||
| update_file("docs/reference/app.md", [(r"^::: project\.app", f"::: {source}.app")]) | ||
| update_file( | ||
| "mkdocs.yml", | ||
| [ | ||
| (r"^repo_name: .*", f"repo_name: {github}/{name}"), | ||
| (r"^repo_url: .*", f"repo_url: https://github.com/{github}/{name}"), | ||
| ], | ||
| ) | ||
| update_file( | ||
| "pyproject.toml", | ||
| [ | ||
| (r"^source = \[.*\]", f'source = ["{source}"]'), | ||
| (r'^app = "project\.app:main"', f'app = "{source}.app:main"'), | ||
| (r'^name = ".*"', f'name = "{source}"'), | ||
| (r'^description = ".*"', f'description = "{escaped_description}"'), | ||
| (r"^authors = \[.*\]", f'authors = ["{escaped_author} <{escaped_email}>"]'), | ||
| ], | ||
| ) | ||
| update_file("docs/README.md", [(r"^# .*", f"# {description}")]) | ||
| update_file(".github/CODEOWNERS", [(r"@.*", f"@{github}")]) | ||
| update_file(".github/FUNDING.yml", [(r"^github: \[.*\]", f"github: [{github}]")]) | ||
|
|
||
|
|
||
| @command(context_settings={"help_option_names": ["-h", "--help"]}) | ||
|
|
||
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.