Skip to content

feat: smartlink redirects directly to CRE when only one CRE is linked#938

Merged
northdpole merged 2 commits into
OWASP:mainfrom
shreeshtripurwarcomp23-coder:fix/smartlink-single-cre-redirect
Jun 24, 2026
Merged

feat: smartlink redirects directly to CRE when only one CRE is linked#938
northdpole merged 2 commits into
OWASP:mainfrom
shreeshtripurwarcomp23-coder:fix/smartlink-single-cre-redirect

Conversation

@shreeshtripurwarcomp23-coder

Copy link
Copy Markdown
Contributor

When a smartlink resolves to a standard section that has exactly one linked CRE, redirect the user directly to that CRE page instead of the intermediate standard-section node page. The CRE page already contains all the information the landing page would show.

If multiple CREs are linked, behaviour is unchanged.

Closes #486
Supercedes #906

Addressed the review comments in #906

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 44442b8b-857e-40f0-87e0-dc0ee6f3cd73

📥 Commits

Reviewing files that changed from the base of the PR and between 91874dc and be608be.

📒 Files selected for processing (2)
  • application/tests/web_main_test.py
  • application/web/web_main.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • application/tests/web_main_test.py
  • application/web/web_main.py

Summary by CodeRabbit

  • Bug Fixes
    • Smart links now redirect more accurately for standard references.
    • When a standard section maps to a single CRE, users are taken directly to that CRE page.
    • If multiple CREs match the same standard, the link now falls back to the standard page instead of choosing one arbitrarily.
    • Improved redirect behavior for missing standards, preserving the existing fallback behavior where available.

Walkthrough

smartlink now redirects to a single linked CRE when a standard node has exactly one CRE link. The route docstring and tests were updated, including a multi-CRE case that keeps the standard-node redirect.

Changes

smartlink Direct CRE Redirect

Layer / File(s) Summary
smartlink CRE redirect logic and docstring
application/web/web_main.py
The smartlink docstring now describes direct CRE redirects and fallback behavior. The route filters matched-node links to CRE doctype entries and redirects to /cre/<id> when exactly one CRE link exists.
Updated test_smartlink assertions
application/tests/web_main_test.py
The CWE/456 and ASVS/v0.1.2 expectations now point to /cre/222-222 and /cre/333-333. A CWEmulti case is added where multiple CRE links keep the redirect on the standard node page.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: redirecting smartlinks directly to a CRE when there is only one linked CRE.
Description check ✅ Passed The description matches the implemented smartlink redirect behavior and the linked issue.
Linked Issues check ✅ Passed The PR implements #486 by redirecting single-CRE smartlinks directly to the CRE page while keeping multi-CRE behavior unchanged.
Out of Scope Changes check ✅ Passed The changes stay focused on smartlink redirect logic and its tests, with no clear unrelated additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
application/tests/web_main_test.py (1)

588-600: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Swap the expected CRE IDs for CWE vs ASVS redirects.

The assertions are inverted relative to fixture setup: CWE is linked through dcd (222-222) and ASVS through dcb (333-333).

Suggested fix
-            self.assertEqual(location, "/cre/333-333")
+            self.assertEqual(location, "/cre/222-222")
@@
-            self.assertEqual(location, "/cre/222-222")
+            self.assertEqual(location, "/cre/333-333")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@application/tests/web_main_test.py` around lines 588 - 600, The expected CRE
IDs in the redirect assertions are inverted based on the fixture setup. In the
test method, swap the expected location values for the CWE and ASVS endpoint
assertions: the CWE redirect (to /smartlink/standard/CWE/v0.1.2) should expect
location /cre/222-222, and the ASVS redirect (to
/smartlink/standard/ASVS/v0.1.2) should expect location /cre/333-333. Change the
first self.assertEqual(location, "/cre/333-333") to expect /cre/222-222 and the
second self.assertEqual(location, "/cre/222-222") to expect /cre/333-333.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@application/tests/web_main_test.py`:
- Around line 588-600: The expected CRE IDs in the redirect assertions are
inverted based on the fixture setup. In the test method, swap the expected
location values for the CWE and ASVS endpoint assertions: the CWE redirect (to
/smartlink/standard/CWE/v0.1.2) should expect location /cre/222-222, and the
ASVS redirect (to /smartlink/standard/ASVS/v0.1.2) should expect location
/cre/333-333. Change the first self.assertEqual(location, "/cre/333-333") to
expect /cre/222-222 and the second self.assertEqual(location, "/cre/222-222") to
expect /cre/333-333.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3e704195-f081-455a-bede-56adb71ae701

📥 Commits

Reviewing files that changed from the base of the PR and between e853cd3 and 1be8166.

📒 Files selected for processing (2)
  • application/tests/web_main_test.py
  • application/web/web_main.py

When a smartlink resolves to a standard section that has exactly one
linked CRE, redirect the user directly to that CRE page instead of
the intermediate standard-section node page. The CRE page already
contains all the information the landing page would show.

If multiple CREs are linked, behaviour is unchanged.

Supersedes OWASP#906
@shreeshtripurwarcomp23-coder shreeshtripurwarcomp23-coder force-pushed the fix/smartlink-single-cre-redirect branch from 91874dc to 1f5f29f Compare June 18, 2026 15:47
@shreeshtripurwarcomp23-coder

Copy link
Copy Markdown
Contributor Author

Verified locally by running python -m pytest application/tests/web_main_test.py::TestMain::test_smartlink -v. The current values (/cre/222-222 for CWE and /cre/333-333 for ASVS) are correct — swapping them back causes the test to fail with AssertionError: '/cre/222-222' != '/cre/333-333'. The static analysis here is incorrect; the actual runtime behavior confirms the current assertions are right.

@northdpole northdpole left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — approving for merge.

Rebased onto current main. Single-CRE smartlink → /cre/{id}; multi-CRE and MITRE fallback unchanged. Closes #486.

@northdpole northdpole merged commit 08387f0 into OWASP:main Jun 24, 2026
6 checks passed
northdpole added a commit that referenced this pull request Jun 24, 2026
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.

Make smartlink go to CRE directly

2 participants