From 408312dbdc3b78d95e638f64125ea1a5b53f6c02 Mon Sep 17 00:00:00 2001 From: Soufiane <13897436+soufianerafik@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:40:07 -0800 Subject: [PATCH] [GH-165] - Prevent double Base64 encoding of profile href + Github Actions updates (#166) * fix(backend): Prevent double Base64 encoding of profile href * fix(ci): Update pull-request.yml * [Bot] Update version to 2.2.8 * fix(ci): Update pull-request.yml:validate-image-quality to use pipx * fix(ci): Bump google auth dependencies on configure-docker/action.yml --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .github/actions/configure-docker/action.yml | 4 ++-- .github/workflows/pull-request.yml | 18 ++++++++++++++---- husky_directory/models/search.py | 20 +++++++++++++++++++- pyproject.toml | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/actions/configure-docker/action.yml b/.github/actions/configure-docker/action.yml index 3569dc20..03d8386e 100644 --- a/.github/actions/configure-docker/action.yml +++ b/.github/actions/configure-docker/action.yml @@ -12,10 +12,10 @@ inputs: runs: using: composite steps: - - uses: google-github-actions/auth@v0 + - uses: google-github-actions/auth@v2 with: credentials_json: ${{ inputs.gcr-token }} - - uses: google-github-actions/setup-gcloud@v1.0.1 + - uses: google-github-actions/setup-gcloud@v2.1.0 # archiving leaving this "with" section, might b a handy reference at a later date. # It was there when the above "uses" was uses: google-github-actions/setup-gcloud@v0 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2a01aa18..620bf53c 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,16 +21,16 @@ jobs: new-version: ${{ steps.update-version.outputs.new-version }} steps: - name: Python Poetry Action - uses: abatilo/actions-poetry@v2.1.6 + run: pipx install poetry - uses: uwit-iam/actions/require-semver-guidance-label@0.1 id: guidance with: github-token: ${{ secrets.GITHUB_TOKEN }} - - uses: uwit-iam/actions/update-pr-branch-version@0.1.16 + - uses: uwit-iam/actions/update-pr-branch-version@0.1.20 with: - github-token: ${{ env.GITHUB_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} version-guidance: ${{ steps.guidance.outputs.guidance }} id: update-version @@ -49,7 +49,17 @@ jobs: with: ref: ${{ github.event.pull_request.head.ref }} - - uses: abatilo/actions-poetry@v2.1.6 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Poetry with pip + run: | + python -m pip install --upgrade pip + python -m pip install poetry + poetry --version + - run: | sudo apt-get -y install jq poetry run pip install tox uw-it-build-fingerprinter diff --git a/husky_directory/models/search.py b/husky_directory/models/search.py index 854e221a..dc59e9ad 100644 --- a/husky_directory/models/search.py +++ b/husky_directory/models/search.py @@ -220,7 +220,25 @@ class Person(DirectoryBaseModel): @validator("href") def b64_encode_href(cls, value: str) -> str: - return base64.b64encode(value.encode("UTF-8")).decode("UTF-8") + """ + Base64 encode href only if not already encoded. + Prevents double-encoding after browser back navigation when href + from previous page state is already encoded. + """ + encoding = "UTF-8" + if not cls._is_base64_encoded(value, encoding): + return base64.b64encode(value.encode(encoding)).decode(encoding) + return value + + @staticmethod + def _is_base64_encoded(value: str, encoding: str = "UTF-8") -> bool: + """ + Check if a string is already base64 encoded. + """ + try: + return base64.b64decode(value.encode(encoding)).decode(encoding) is not None + except (ValueError, UnicodeDecodeError): + return False @validator("sort_key", always=True) def set_default_sort_key(cls, v: Optional[str], values: Dict): diff --git a/pyproject.toml b/pyproject.toml index 4fba84ef..9a4ee93c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "uw-husky-directory" -version = "2.2.7" +version = "2.2.8" description = "An updated version of the UW Directory" authors = ["Thomas Thorogood "] license = "MIT"