Skip to content

OTWO-7716 CWE-79/CWE-20: javascript: URI accepted in Homepage URL fie… - #1948

Open
Niharika1117 wants to merge 2 commits into
stagingfrom
OTWO-7716
Open

OTWO-7716 CWE-79/CWE-20: javascript: URI accepted in Homepage URL fie…#1948
Niharika1117 wants to merge 2 commits into
stagingfrom
OTWO-7716

Conversation

@Niharika1117

Copy link
Copy Markdown
Contributor

…ld — no scheme allowlist in validator; unsafe href rendering in profile views

…ld — no scheme allowlist in validator; unsafe href rendering in profile views

Copilot AI left a comment

Copy link
Copy Markdown

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 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#url at 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 thread app/views/accounts/show/_header.html.haml Outdated
Comment thread app/views/accounts/edit.html.haml Outdated
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)

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.

2 participants