Skip to content

Conversation

@petesfrench
Copy link
Contributor

Done

  • Implements cookie service flask extension for integration with cookies.canonical.com
  • Bumps cookie-policy npm package to 3.8.1
  • Implement basic flask-caching to store health status of cookies.canonical.com

QA

  • Check out this feature branch
  • Run the site using the command ./run serve or dotrun
  • View the site locally in your web browser at: http://0.0.0.0:8001/
    • Be sure to test on mobile, tablet and desktop screen sizes
  • [List additional steps to QA the new features or prove the bug has been resolved]

Issue / Card

Fixes #

Screenshots

[If relevant, please include a screenshot.]

Help

QA steps - Commit guidelines

Copilot AI review requested due to automatic review settings December 1, 2025 09:13
@webteam-app
Copy link

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements cross-domain cookie sharing by integrating a cookie service Flask extension with cookies.canonical.com. The implementation includes upgrading the cookie-policy npm package, adding Flask-Caching for health status monitoring, and configuring the necessary session and cookie consent settings.

  • Updates cookie-policy package from version 3.7.x to 3.8.0
  • Adds canonicalwebteam.cookie-service and Flask-Caching Python dependencies
  • Configures Flask session and cookie service with caching support

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
package.json Updates @canonical/cookie-policy dependency to 3.8.0 with exact version pinning
yarn.lock Reflects the updated cookie-policy package version and integrity hash
requirements.txt Adds canonicalwebteam.cookie-service (1.0.0) and Flask-Caching (2.1.0) dependencies
webapp/app.py Implements cookie service initialization with Flask-Caching, session configuration, and cache helper functions
konf/site.yaml Adds COOKIE_SERVICE_API_KEY environment variable from Kubernetes secrets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

app.config["PREFERENCES_COOKIE_EXPIRY_DAYS"] = 365

# Initialize Flask-Caching
app.config["CACHE_TYPE"] = "SimpleCache"
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

SimpleCache is not thread-safe and should not be used in production environments. According to Flask-Caching documentation, SimpleCache is only suitable for development. For production, consider using RedisCache, MemcachedCache, or FileSystemCache. This is particularly important since the cookie service health check runs in the background and could cause race conditions.

Suggested change
app.config["CACHE_TYPE"] = "SimpleCache"
app.config["CACHE_TYPE"] = "FileSystemCache"
app.config["CACHE_DIR"] = "/tmp/flask_cache"

Copilot uses AI. Check for mistakes.
"dependencies": {
"@axe-core/playwright": "^4.8.5",
"@canonical/cookie-policy": "^3.7.4",
"@canonical/cookie-policy": "3.8.0",
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The version specifier has changed from a flexible semantic version range (^3.7.4) to an exact version pin (3.8.0). This inconsistency with other dependencies (which use flexible ranges like ^) may make future updates more difficult. Consider using ^3.8.0 or ~3.8.0 to allow automatic patch updates while maintaining the current minor version, consistent with other dependencies like @canonical/global-nav.

Suggested change
"@canonical/cookie-policy": "3.8.0",
"@canonical/cookie-policy": "^3.8.0",

Copilot uses AI. Check for mistakes.
"dependencies": {
"@axe-core/playwright": "^4.8.5",
"@canonical/cookie-policy": "^3.7.4",
"@canonical/cookie-policy": "3.8.0",
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

The PR description states that the cookie-policy package should be bumped to version 3.8.1, but the actual version in the code is 3.8.0. Please update to 3.8.1 to match the PR description, or update the description if 3.8.0 is the intended version.

Suggested change
"@canonical/cookie-policy": "3.8.0",
"@canonical/cookie-policy": "3.8.1",

Copilot uses AI. Check for mistakes.
Comment on lines +269 to +299
# Configuration for shared cookie service

# Configure Flask session
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=365)
app.config["SESSION_COOKIE_SAMESITE"] = "Lax"
app.config["SESSION_COOKIE_HTTPONLY"] = True
app.config["SESSION_COOKIE_SECURE"] = True

# Number of days before preference cookies expire (default: 365)
app.config["PREFERENCES_COOKIE_EXPIRY_DAYS"] = 365

# Initialize Flask-Caching
app.config["CACHE_TYPE"] = "SimpleCache"
cache = Cache(app)


# Set up cache functions for cookie consent service
def get_cache(key):
return cache.get(key)


def set_cache(key, value, timeout):
cache.set(key, value, timeout)


cookie_service = CookieConsent().init_app(
app,
get_cache_func=get_cache,
set_cache_func=set_cache,
start_health_check=True,
)
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

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

Missing documentation for the cookie service configuration. Consider adding comments explaining:

  • What the COOKIE_SERVICE_API_KEY environment variable is used for (defined in konf/site.yaml but not explicitly referenced here)
  • The purpose of each configuration option
  • Why SimpleCache is being used and its limitations for production deployments

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.24%. Comparing base (ad88ce4) to head (520ab84).

Files with missing lines Patch % Lines
webapp/app.py 80.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15849   +/-   ##
=======================================
  Coverage   48.24%   48.24%           
=======================================
  Files          37       37           
  Lines        5615     5615           
=======================================
  Hits         2709     2709           
  Misses       2906     2906           
Files with missing lines Coverage Δ
webapp/app.py 85.18% <80.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants