Skip to content

Commit

Permalink
[GH-165] - Prevent double Base64 encoding of profile href + Github Ac…
Browse files Browse the repository at this point in the history
…tions 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>
  • Loading branch information
soufianerafik and github-actions[bot] authored Jan 16, 2025
1 parent ef5ea2b commit 408312d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/actions/configure-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
id: guidance
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- uses: uwit-iam/actions/[email protected].16
- uses: uwit-iam/actions/[email protected].20
with:
github-token: ${{ env.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
version-guidance: ${{ steps.guidance.outputs.guidance }}
id: update-version

Expand All @@ -49,7 +49,17 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}

- uses: abatilo/[email protected]
- 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
Expand Down
20 changes: 19 additions & 1 deletion husky_directory/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 408312d

Please sign in to comment.