Skip to content

feat(shortener): public redirect + async click tracking + QR + analytics (B3-B4)#65

Open
PenguinzTech wants to merge 1 commit into
feature/shortener-apifrom
feature/shortener-redirect-analytics
Open

feat(shortener): public redirect + async click tracking + QR + analytics (B3-B4)#65
PenguinzTech wants to merge 1 commit into
feature/shortener-apifrom
feature/shortener-redirect-analytics

Conversation

@PenguinzTech

Copy link
Copy Markdown
Contributor

Feature (Track B, part 2) — redirect, tracking, QR, analytics

Stacked on #63 (base = feature/shortener-api). Targets release/v0.1.x.

  • Redirect (app/redirect.py) — public GET /<short_code>302 to long_url (404 for unknown/inactive/expired); destination re-validated before redirect. Click tracking is non-blocking (asyncio.create_task after the response); click_count incremented atomically. link_clicks stores ip_hash (salted SHA256, never raw IP) + UA-parsed device/browser/os + referer.
  • QRGET /api/v1/urls/<id>/qr (auth + urls:read + tenant-scoped) returns an on-demand PNG of the short URL (qrcode+Pillow), not stored. Branded/color QR left as a Professional-tier TODO.
  • Analytics (app/analytics.py) — /analytics/urls/<id> (per-link: total, clicks-by-day, top referers) and /analytics/summary (tenant totals, top links, time series), analytics:read + tenant-scoped. Basic tiers implemented; geo/device/browser breakdowns marked TODO(tiering) for the Enterprise advanced-analytics gate.
  • deps: qrcode, Pillow, user-agents (pinned + hashed via uv).

Tests

619 passed, 90.66% coverage — redirect/404/expiry, async click + ip_hash (no raw IP), QR png bytes, analytics date-filter/pagination/tenant-isolation.

🤖 Generated with Claude Code

…ics (B3-B4)

- app/redirect.py: public GET /<short_code> → 302 to long_url (404 for unknown/
  inactive/expired), destination re-validated before redirect. Click tracking is
  non-blocking (asyncio.create_task after the response); click_count incremented
  atomically. link_clicks stores ip_hash (salted SHA256, never raw IP) + UA-parsed
  device/browser/os + referer.
- QR: GET /api/v1/urls/<id>/qr (auth + urls:read + tenant-scoped) returns on-demand
  PNG of the short URL (qrcode+Pillow), not stored. TODO(tiering) branded/color QR.
- app/analytics.py: /analytics/urls/<id> (per-link: total, clicks-by-day, top referers)
  and /analytics/summary (tenant-wide totals, top links, time series), analytics:read +
  tenant-scoped. Basic tiers implemented; geo/device/browser breakdowns marked
  TODO(tiering) for the Enterprise advanced-analytics gate.
- deps: qrcode, Pillow, user-agents (pinned+hashed via uv).

Tests: 619 passed, 90.66% coverage — redirect/404/expiry, async click + ip_hash,
QR png, analytics date-filter/pagination/tenant-isolation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PenguinzTech PenguinzTech added this to the v0.1.x milestone Jul 14, 2026
@PenguinzTech PenguinzTech added the type:feature New feature label Jul 14, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @PenguinzTech, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​user-agents@​2.2.010010010075100
Addedpypi/​ua-parser@​1.0.2100100100100100
Addedpypi/​ua-parser-builtins@​202606100100100100100

View full report

@socket-security

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn Low
Filesystem access: pypi ua-parser

Location: Package overview

From: services/flask-backend/requirements.txtpypi/ua-parser@1.0.2

ℹ Read more on: This package | This alert | What is filesystem access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: If a package must read the file system, clarify what it will read and ensure it reads only what it claims to. If appropriate, packages can leave file system access to consumers and operate on data passed to it instead.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore pypi/ua-parser@1.0.2. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Filesystem access: pypi user-agents

Location: Package overview

From: services/flask-backend/requirements.txtpypi/user-agents@2.2.0

ℹ Read more on: This package | This alert | What is filesystem access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: If a package must read the file system, clarify what it will read and ensure it reads only what it claims to. If appropriate, packages can leave file system access to consumers and operate on data passed to it instead.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore pypi/user-agents@2.2.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Unmaintained: pypi user-agents was last published 6 years ago

Last Publish: 8/23/2020, 6:01:54 AM

From: services/flask-backend/requirements.txtpypi/user-agents@2.2.0

ℹ Read more on: This package | This alert | What are unmaintained packages?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Package should publish periodic maintenance releases if they are maintained, or deprecate if they have no intention in further maintenance.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore pypi/user-agents@2.2.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant