![Sonatype Logo Full Color](https://www.sonatype.com/hubfs/Sonatype_logo_full_color.png)
Namespace confusion: Minimizing risk with Sonatype Nexus Repository
4 minute read time
![](https://www.sonatype.com/hubfs/DevSecOpsDays.com%20master/Imported_Blog_Media/GettyImages-155438989.jpg)
In case you're here and you're not sure why you should care about namespaces and routing rules, I highly recommend you start here.
Ok now that you know why this matters, let's talk about ways that you can use Sonatype Nexus Repository to help minimize your risk.
How to protect yourself with Sonatype Nexus Repository
If you're using Sonatype Nexus Repository 3, you can protect your organization immediately using a feature called repository routing rules.
Routing rules let you specify which components can be downloaded from which repositories, using regular expressions that filter component paths. This can be used to prevent coordinates associated with your own organization from being fetched from remote repositories.
Here is an example routing rule that blocks any Sonatype-namespaced Java components from being fetched from a proxy of maven central:
The regular expression you need varies from ecosystem to ecosystem, because the repository/path structures are different. Here are examples for npm, PyPI, RubyGems and NuGet.
Blocking an entire namespace
Blocking org-internal coordinates is a lot easier if you're using namespaces that clearly identify components made by your organization. npm coordinates can have explicit namespaces, so you can filter them with a single expression:
Ecosystem |
Blocking Rule for a Namespace/Scope |
npm |
^/@sonatype/.*$ |
Blocking by component name prefix
Some ecosystems don't support explicit namespaces, but in many cases component names have a prefix that identifies the publishing organization.
Ecosystem |
Blocking Rule for a Component Name Prefix |
PyPI |
^/.*/importlib_.*$ |
RubyGems |
^/.*/rspec-.*$ |
NuGet |
^/DotNetNuke\..*$ |
Blocking specific components
If your organization creates components that are neither namespaced nor prefixed, you've got more work to do. You'll need to create a blocking matcher for every component that your organization uses:
Ecosystem |
Component Name |
npm |
^/ajv/.*$ |
PyPI |
^/.*/peppercorn-.*$ |
RubyGems |
^/.*/activesupport-.*$ |
NuGet |
^/angularjs/.*$ |
Testing your rules
Sonatype Nexus Repository comes with a global routing rules preview so you can easily tell what will be fetched from where. This is an example test to ensure that a Sonatype-specific component (nexus audit) will never be fetched from Maven Central.
If you're concerned about components that are already cached in your proxy repositories, there's no need to worry: blocking rules don't just prevent remote fetches, they prevent matching components from being served at all.
![Picture of Michael Prescott](https://www.sonatype.com/hubfs/michael%20prescott%20bio%20(1).png)
Written by Michael Prescott
Michael is Director of Product for Sonatype Nexus Repository, where he helps make DevOps easy for software development organizations, large and small.
Explore All Posts by Michael PrescottRelated Resources
![Summer of Software-04](https://www.sonatype.com/hubfs/Summer%20of%20Software-04.png)
![Summer of Software-04](https://www.sonatype.com/hubfs/Summer%20of%20Software-04.png)
![](https://www.sonatype.com/hubfs/GettyImages-183764017.jpg)