Skip to content

Commit

Permalink
Create short redirect link format for vulnerabilities. (#952)
Browse files Browse the repository at this point in the history
https://osv.dev/VULN-ID would redirect to
https://osv.dev/vulnerability/VULN-ID, if VULN-ID exists.

Fixes #930.
  • Loading branch information
oliverchang committed Jan 9, 2023
1 parent 6ebc5c4 commit b8f3e6e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion gcp/appengine/frontend_handlers.py
Expand Up @@ -40,7 +40,9 @@
_PAGE_SIZE = 16
_PAGE_LOOKAHEAD = 4
_REQUESTS_PER_MIN = 30
_VALID_BLOG_NAME = re.compile(r'^[\w-]+$')
_WORD_CHARACTERS_OR_DASH = re.compile(r'^[\w-]+$')
_VALID_BLOG_NAME = _WORD_CHARACTERS_OR_DASH
_VALID_VULN_ID = _WORD_CHARACTERS_OR_DASH
_BLOG_CONTENTS_DIR = 'blog'

if utils.is_prod():
Expand Down Expand Up @@ -171,6 +173,21 @@ def vulnerability(vuln_id):
return render_template('vulnerability.html', vulnerability=vuln)


@blueprint.route('/<potential_vuln_id>')
def vulnerability_redirector(potential_vuln_id):
"""Convenience redirector for /VULN-ID to /vulnerability/VULN-ID."""
if not _VALID_VULN_ID.match(potential_vuln_id):
abort(404)
return None

vuln = osv_get_by_id(potential_vuln_id)
if vuln:
return redirect(f'/vulnerability/{potential_vuln_id}')

abort(404)
return None


def bug_to_response(bug, detailed=True):
"""Convert a Bug entity to a response object."""
response = osv.vulnerability_to_dict(bug.to_vulnerability())
Expand Down

0 comments on commit b8f3e6e

Please sign in to comment.