The fourth-corner analysis aims to quantify and test for relationships between species traits and site-specific environmental variables, mediated by site-specific species abundances. Since there is no common unit of observation, the significance of the relationships is tested using a double permutation procedure (site based and species based). This method implies that all species and sites are independent of each other. However, this fundamental hypothesis might be flawed because of phylogenetic relatedness between species and spatial autocorrelation in the environmental data. Here, using a simulation-based experiment, we demonstrate how the presence of spatial and phylogenetic autocorrelations can, in some circumstances, lead to inflated type I error rates, suggesting that signifi- cant associations can be misidentified. As an alternative, we propose a new randomization approach designed to avoid this issue, based on Moran’s spectral randomization. In this approach, standard permutations are replaced by constrained randomizations so that the distribution of the statistic under the null hypothesis is built with additional constraints to preserve the phylogenetic and spatial structures of the observed data. The inclusion of this new randomization approach provides total control over type I error rates and should be used in real studies where spatial and phylogenetic autocorrelations often occur.