OTWO-7716 CWE-79/CWE-20: javascript: URI accepted in Homepage URL fie… - #1948
Open
Niharika1117 wants to merge 2 commits into
Open
OTWO-7716 CWE-79/CWE-20: javascript: URI accepted in Homepage URL fie…#1948Niharika1117 wants to merge 2 commits into
Niharika1117 wants to merge 2 commits into
Conversation
…ld — no scheme allowlist in validator; unsafe href rendering in profile views
There was a problem hiding this comment.
Pull request overview
This PR aims to address CWE-79/CWE-20 risk around account “Homepage URL” handling by restricting accepted URL schemes and preventing unsafe href rendering in account profile views.
Changes:
- Adds a scheme allowlist check for
Account#urlat the model layer and updates validation messaging. - Updates account header partials to only render the homepage link when the URL starts with an allowed scheme.
- Adds client-side URL field validation (JS + styling) and help text/pattern guidance on the edit form.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| config/locales/accounts.en.yml | Adds i18n strings for scheme allowlist validation and form help text. |
| app/views/accounts/show/_header.html.haml | Restricts homepage link rendering to allowed schemes. |
| app/views/accounts/edit.html.haml | Adds URL input pattern/title/help text and client-side validation hook class. |
| app/views/accounts/_mini_header.html.haml | Restricts homepage link rendering to allowed schemes. |
| app/models/concerns/account_validations.rb | Adds an explicit scheme allowlist validation to Account#url. |
| app/assets/stylesheets/account_form_validation.scss | Adds styling for valid/invalid URL input states. |
| app/assets/javascripts/account_form_validation.js.coffee | Adds client-side URL scheme validation on the account form. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+14
to
+15
| validates :url, length: { maximum: 100 }, url_format: true, allow_blank: true, | ||
| format: { with: %r{\A(https?|ftp)://}, message: :invalid_format, allow_blank: true } |
Comment on lines
+48
to
+50
| - valid_url = @account.url&.match?(%r{\A(https?|ftp)://}) ? @account.url : nil | ||
| = f.text_field :url, class: 'form-control validate-url', value: valid_url, | ||
| pattern: '(https?|ftp)://.*', title: t('accounts.edit.valid_url_format') |
Comment on lines
+1
to
+10
| document.addEventListener 'DOMContentLoaded', -> | ||
| urlField = document.querySelector('input[name="account[url]"]') | ||
| form = document.querySelector('form[action*="/accounts/"]') | ||
|
|
||
| return unless urlField && form | ||
|
|
||
| validateUrl = (value) -> | ||
| return true unless value | ||
| /^(https?|ftp):\/\//.test(value) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ld — no scheme allowlist in validator; unsafe href rendering in profile views