8000 Fix issues w/ Rust security by jmahmood · Pull Request #22 · jmahmood/CardBrick · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[advisories]
ignore = [
# quick-xml is pulled transitively through eframe/winit's Linux desktop
# accessibility and Wayland support. Fixing this requires a coordinated
# desktop UI stack upgrade rather than a small lockfile-only update.
"RUSTSEC-2026-0194",
"RUSTSEC-2026-0195",
]
33 changes: 22 additions & 11 deletions .github/workflows/sprint4-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
Expand Down Expand Up @@ -71,8 +76,11 @@ jobs:

- name: Run type checking
run: |
mypy cardbrick-syncd/ --ignore-missing-imports
mypy cardbrick-cli/ --ignore-missing-imports
tmpdir="$(mktemp -d)"
cp -R cardbrick-syncd "$tmpdir/cardbrick_syncd"
cp -R cardbrick-cli "$tmpdir/cardbrick_cli"
mypy "$tmpdir/cardbrick_syncd" --ignore-missing-imports
mypy "$tmpdir/cardbrick_cli" --ignore-missing-imports

- name: Test CLI import functionality
run: |
Expand Down Expand Up @@ -176,12 +184,12 @@ jobs:
--home-dir /var/lib/cardbrick --create-home cardbrick-sync

# Copy Python daemon
COPY cardbrick-syncd/ /app/cardbrick-syncd/
COPY cardbrick-cli/ /app/cardbrick-cli/
COPY cardbrick-syncd/ /app/cardbrick_syncd/
COPY cardbrick-cli/ /app/cardbrick_cli/

# Install Python dependencies
RUN pip install -r /app/cardbrick-syncd/requirements.txt
RUN pip install -r /app/cardbrick-cli/requirements.txt
RUN pip install -r /app/cardbrick_syncd/requirements.txt
RUN pip install -r /app/cardbrick_cli/requirements.txt

# Set up directories
RUN mkdir -p /var/lib/cardbrick/{inbox,keys/devices}
Expand All @@ -198,11 +206,14 @@ jobs:

# Handheld Dockerfile (Rust client)
cat > tests/Dockerfile.handheld << 'EOF'
FROM rust:1.75-slim
FROM rust:slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
pkg-config \
libasound2-dev \
libssl-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -283,12 +294,12 @@ jobs:

- name: Run integration tests
run: |
docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit
docker compose -f docker-compose.test.yml up --build --abort-on-container-exit

- name: Collect test results
if: always()
run: |
docker-compose -f docker-compose.test.yml logs > integration-test-logs.txt
docker compose -f docker-compose.test.yml logs > integration-test-logs.txt

- name: Upload test logs
if: always()
Expand All @@ -300,7 +311,7 @@ jobs:
- name: Cleanup
if: always()
run: |
docker-compose -f docker-compose.test.yml down -v
docker compose -f docker-compose.test.yml down -v

# Security audit
security-audit:
Expand Down Expand Up @@ -334,4 +345,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: security-reports
path: "*-report.json"
path: "*-report.json"
65 changes: 34 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ uuid = { version = "1.0", features = ["v4"] }

# Networking for sync (Sprint 4)
reqwest = { version = "0.11", features = ["json"] }
ring = "0.16"
ring = "0.17.12"
tokio = { version = "1.0", features = ["rt", "rt-multi-thread", "macros"] }
hex = "0.4"

Expand Down Expand Up @@ -116,4 +116,3 @@ assets = [
["assets/desktop/cardbrick-desktop.desktop", "usr/share/applications/", "644"],
["README.md", "usr/share/doc/cardbrick-desktop/", "644"],
]

4 changes: 2 additions & 2 deletions cardbrick-cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def status(ctx):
daemon_status = result.stdout.strip()
status_icon = "✓" if daemon_status == "active" else "❌"
click.echo(f"Sync daemon: {status_icon} {daemon_status}")
except:
except Exception:
click.echo("Sync daemon: Status unknown")

except Exception as e:
Expand Down Expand Up @@ -289,4 +289,4 @@ def main():
cli()

if __name__ == '__main__':
main()
main()
14 changes: 4 additions & 10 deletions cardbrick-cli/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from datetime import datetime

import pandas as pd
import markdown

logger = logging.getLogger(__name__)

Expand All @@ -23,8 +22,8 @@ class Card:
"""Represents a single flashcard"""
front: str
back: str
tags: List[str] = None
media: List[str] = None
tags: Optional[List[str]] = None
media: Optional[List[str]] = None

def __post_init__(self):
if self.tags is None:
Expand Down Expand Up @@ -138,8 +137,6 @@ def import_file(self, file_path: Path, deck_name: Optional[str] = None) -> CBDec

def _detect_csv_format(self, columns: List[str]) -> Tuple[str, str, Optional[str]]:
"""Detect CSV format and return column mappings"""
col_map = {col: col for col in columns}

# Common front/back mappings
front_ 10BC8 mappings = {
'front': ['front', 'question', 'term', 'word', 'prompt'],
Expand Down Expand Up @@ -285,10 +282,6 @@ def _parse_header_qa(self, content: str) -> List[Card]:
"""Parse Q&A pairs using markdown headers"""
cards = []

# Convert to HTML and parse
md = markdown.Markdown()
html = md.convert(content)

# Simple parsing - look for header patterns
lines = content.split('\n')
current_question = None
Expand Down Expand Up @@ -384,6 +377,7 @@ def import_file(file_path: Path, output_dir: Path, deck_name: Optional[str] = No
output_dir = Path(output_dir)

# Determine importer based on file extension
importer: Any
if file_path.suffix.lower() == '.csv':
importer = CSVImporter()
elif file_path.suffix.lower() in ['.md', '.markdown']:
Expand All @@ -406,4 +400,4 @@ def import_file(file_path: Path, output_dir: Path, deck_name: Optional[str] = No
deck_hash = exporter.calculate_deck_hash(deck)
logger.info(f"Deck hash: {deck_hash}")

return output_path
return output_path
1 change: 0 additions & 1 deletion cardbrick-py/cardbrick/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

import pygame

from . import __version__
from .bootlog import (log_display_diagnostics, log_pygame_versions)
from .importer import ApkgError, import_apkg
from .input_map import (FACE_LABELS, InputMap, InputTranslator,
Expand Down
2 changes: 1 addition & 1 deletion cardbrick-py/cardbrick/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import os
from datetime import datetime, timezone
from datetime import datetime

import pygame

Expand Down
4 changes: 2 additions & 2 deletions cardbrick-syncd/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
try:
from .config import Config
except ImportError:
from config import Config
from config import Config # type: ignore[no-redef]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -213,4 +213,4 @@ def get_daemon_public_key_pem(self) -> bytes:
return self.daemon_public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
)
Loading
Loading
0